public void Can_get_and_set_column_property()
        {
            var column = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), column);

            Assert.Same(column, scalarPropertyMapping.Column);

            column = new EdmProperty("C'", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));

            scalarPropertyMapping.Column = column;

            Assert.Same(column, scalarPropertyMapping.Column);
        }
        public void Can_get_property_mappings()
        {
            var endPropertyMapping = new EndPropertyMapping();

            Assert.Empty(endPropertyMapping.PropertyMappings);

            var scalarPropertyMapping
                = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            endPropertyMapping.AddPropertyMapping(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, endPropertyMapping.PropertyMappings.Single());
        }
        public void Cannot_add_property_when_read_only()
        {
            var complexType = new ComplexType();
            var complexTypeMapping = new ComplexTypeMapping(complexType);

            complexTypeMapping.SetReadOnly();

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => complexTypeMapping.AddPropertyMapping(scalarPropertyMapping)).Message);
        }
        public void Cannot_add_property_when_read_only()
        {
            var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace));
            var mapping = new EndPropertyMapping(associationEnd);
            mapping.SetReadOnly();

            Assert.True(mapping.IsReadOnly);

            var scalarPropertyMapping
                = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => mapping.AddPropertyMapping(scalarPropertyMapping)).Message);
        }
        public void Can_add_remove_properties()
        {
            var complexType = new ComplexType();
            var complexTypeMapping = new ComplexTypeMapping(complexType);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            Assert.Empty(complexTypeMapping.PropertyMappings);

            complexTypeMapping.AddPropertyMapping(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, complexTypeMapping.PropertyMappings.Single());

            complexTypeMapping.RemovePropertyMapping(scalarPropertyMapping);

            Assert.Empty(complexTypeMapping.PropertyMappings);
        }
        public void Setting_column_should_update_property_mapping()
        {
            var columnProperty1 = new EdmProperty("C1", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));
            var property = new EdmProperty("P");
            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty1, new[] { property });
            var scalarPropertyMapping = new ScalarPropertyMapping(property, columnProperty1);

            columnMappingBuilder.SetTarget(scalarPropertyMapping);

            var columnProperty2 = new EdmProperty("C2", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));

            columnMappingBuilder.ColumnProperty = columnProperty2;

            Assert.Same(columnProperty2, columnMappingBuilder.ColumnProperty);
            Assert.Same(columnProperty2, scalarPropertyMapping.Column);
        }
        public void Can_add_get_remove_properties()
        {
            var endPropertyMapping = new EndPropertyMapping();

            Assert.Empty(endPropertyMapping.Properties);

            var scalarPropertyMapping
                = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));

            endPropertyMapping.AddProperty(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, endPropertyMapping.Properties.Single());

            endPropertyMapping.RemoveProperty(scalarPropertyMapping);

            Assert.Empty(endPropertyMapping.Properties);
        }
        public void Cannot_remove_property_when_read_only()
        {
            var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace));
            var mapping        = new EndPropertyMapping(associationEnd);
            var scalarPropertyMapping
                = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));

            mapping.AddProperty(scalarPropertyMapping);
            mapping.SetReadOnly();

            Assert.True(mapping.IsReadOnly);

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => mapping.RemoveProperty(scalarPropertyMapping)).Message);
        }
Ejemplo n.º 9
0
        internal void AddColumnMapping(ColumnMappingBuilder columnMappingBuilder)
        {
            Check.NotNull <ColumnMappingBuilder>(columnMappingBuilder, nameof(columnMappingBuilder));
            if (!columnMappingBuilder.PropertyPath.Any <EdmProperty>() || this._columnMappings.Contains(columnMappingBuilder))
            {
                throw new ArgumentException(Strings.InvalidColumnBuilderArgument((object)"columnBuilderMapping"));
            }
            this._columnMappings.Add(columnMappingBuilder);
            StructuralTypeMapping structuralTypeMapping = (StructuralTypeMapping)this;
            int         index;
            EdmProperty property;

            for (index = 0; index < columnMappingBuilder.PropertyPath.Count - 1; ++index)
            {
                property = columnMappingBuilder.PropertyPath[index];
                ComplexPropertyMapping complexPropertyMapping = structuralTypeMapping.PropertyMappings.OfType <ComplexPropertyMapping>().SingleOrDefault <ComplexPropertyMapping>((Func <ComplexPropertyMapping, bool>)(pm => object.ReferenceEquals((object)pm.Property, (object)property)));
                ComplexTypeMapping     typeMapping            = (ComplexTypeMapping)null;
                if (complexPropertyMapping == null)
                {
                    typeMapping = new ComplexTypeMapping(false);
                    typeMapping.AddType(property.ComplexType);
                    complexPropertyMapping = new ComplexPropertyMapping(property);
                    complexPropertyMapping.AddTypeMapping(typeMapping);
                    structuralTypeMapping.AddPropertyMapping((PropertyMapping)complexPropertyMapping);
                }
                structuralTypeMapping = (StructuralTypeMapping)(typeMapping ?? complexPropertyMapping.TypeMappings.Single <ComplexTypeMapping>());
            }
            property = columnMappingBuilder.PropertyPath[index];
            ScalarPropertyMapping scalarPropertyMapping1 = structuralTypeMapping.PropertyMappings.OfType <ScalarPropertyMapping>().SingleOrDefault <ScalarPropertyMapping>((Func <ScalarPropertyMapping, bool>)(pm => object.ReferenceEquals((object)pm.Property, (object)property)));

            if (scalarPropertyMapping1 == null)
            {
                ScalarPropertyMapping scalarPropertyMapping2 = new ScalarPropertyMapping(property, columnMappingBuilder.ColumnProperty);
                structuralTypeMapping.AddPropertyMapping((PropertyMapping)scalarPropertyMapping2);
                columnMappingBuilder.SetTarget(scalarPropertyMapping2);
            }
            else
            {
                scalarPropertyMapping1.Column = columnMappingBuilder.ColumnProperty;
            }
        }
Ejemplo n.º 10
0
            public static string GetIdentity(PropertyMapping mapping)
            {
                ScalarPropertyMapping mapping1 = mapping as ScalarPropertyMapping;

                if (mapping1 != null)
                {
                    return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping1));
                }
                ComplexPropertyMapping mapping2 = mapping as ComplexPropertyMapping;

                if (mapping2 != null)
                {
                    return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping2));
                }
                EndPropertyMapping mapping3 = mapping as EndPropertyMapping;

                if (mapping3 != null)
                {
                    return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping3));
                }
                return(BaseMetadataMappingVisitor.IdentityHelper.GetIdentity((ConditionPropertyMapping)mapping));
            }
        public void Setting_column_should_update_property_mapping()
        {
            var columnProperty1 = new EdmProperty("C1", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            }));
            var property              = new EdmProperty("P");
            var columnMappingBuilder  = new ColumnMappingBuilder(columnProperty1, new[] { property });
            var scalarPropertyMapping = new ScalarPropertyMapping(property, columnProperty1);

            columnMappingBuilder.SetTarget(scalarPropertyMapping);

            var columnProperty2 = new EdmProperty("C2", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            }));

            columnMappingBuilder.ColumnProperty = columnProperty2;

            Assert.Same(columnProperty2, columnMappingBuilder.ColumnProperty);
            Assert.Same(columnProperty2, scalarPropertyMapping.Column);
        }
Ejemplo n.º 12
0
        public void Can_add_and_remove_properties()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.PropertyMappings);

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, mappingFragment.PropertyMappings.Single());

            mappingFragment.RemovePropertyMapping(scalarPropertyMapping);

            Assert.Empty(mappingFragment.PropertyMappings);
        }
Ejemplo n.º 13
0
        public void Cannot_add_property_when_read_only()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            mappingFragment.SetReadOnly();

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => mappingFragment.AddPropertyMapping(scalarPropertyMapping)).Message);
        }
Ejemplo n.º 14
0
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));
            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);
            mappingFragment.AddCondition(conditionMapping);

            Assert.False(scalarPropertyMapping.IsReadOnly);
            Assert.False(conditionMapping.IsReadOnly);
            mappingFragment.SetReadOnly();
            Assert.True(scalarPropertyMapping.IsReadOnly);
            Assert.True(conditionMapping.IsReadOnly);
        }
Ejemplo n.º 15
0
        public void AddColumnMapping(ColumnMappingBuilder columnMappingBuilder)
        {
            Check.NotNull(columnMappingBuilder, "columnMappingBuilder");
            if (!columnMappingBuilder.PropertyPath.Any() ||
                _columnMappings.Contains(columnMappingBuilder))
            {
                throw new ArgumentException(Strings.InvalidColumnBuilderArgument("columnBuilderMapping"));
            }

            DebugCheck.NotNull(columnMappingBuilder.ColumnProperty);

            _columnMappings.Add(columnMappingBuilder);

            StructuralTypeMapping structuralTypeMapping = this;
            EdmProperty           property;

            // Turn the property path into a mapping fragment nested tree structure.

            var i = 0;

            for (; i < columnMappingBuilder.PropertyPath.Count - 1; i++)
            {
                // The first n-1 properties are complex so we just need to build
                // a corresponding tree of complex type mappings.

                property = columnMappingBuilder.PropertyPath[i];

                var complexPropertyMapping
                    = structuralTypeMapping
                      .PropertyMappings
                      .OfType <ComplexPropertyMapping>()
                      .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

                ComplexTypeMapping complexTypeMapping = null;

                if (complexPropertyMapping == null)
                {
                    complexTypeMapping = new ComplexTypeMapping(false);
                    complexTypeMapping.AddType(property.ComplexType);

                    complexPropertyMapping = new ComplexPropertyMapping(property);
                    complexPropertyMapping.AddTypeMapping(complexTypeMapping);

                    structuralTypeMapping.AddPropertyMapping(complexPropertyMapping);
                }

                structuralTypeMapping
                    = complexTypeMapping
                      ?? complexPropertyMapping.TypeMappings.Single();
            }

            // The last property has to be a scalar mapping to the target column.
            // Extract it and create the scalar mapping leaf node, ensuring that we
            // set the target column.

            property = columnMappingBuilder.PropertyPath[i];

            var scalarPropertyMapping
                = structuralTypeMapping
                  .PropertyMappings
                  .OfType <ScalarPropertyMapping>()
                  .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

            if (scalarPropertyMapping == null)
            {
                scalarPropertyMapping
                    = new ScalarPropertyMapping(property, columnMappingBuilder.ColumnProperty);

                structuralTypeMapping.AddPropertyMapping(scalarPropertyMapping);

                columnMappingBuilder.SetTarget(scalarPropertyMapping);
            }
            else
            {
                scalarPropertyMapping.Column = columnMappingBuilder.ColumnProperty;
            }
        }
Ejemplo n.º 16
0
 public static string GetIdentity(ScalarPropertyMapping mapping)
 {
     return("ScalarProperty(Identity=" + mapping.Property.Identity
            + ",ColumnIdentity=" + mapping.Column.Identity + ")");
 }
        protected override void Visit(ScalarPropertyMapping scalarPropertyMapping)
        {
            int index;
            if (!AddObjectToSeenListAndHashBuilder(scalarPropertyMapping, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(scalarPropertyMapping, index);

            #region Inner data visit

            base.Visit(scalarPropertyMapping);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
        public static void GetIdentity_of_StorageScalarPropertyMapping_returns_expected_value()
        {
            var typeUsage = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var property1 = new EdmProperty("A", typeUsage);
            var property2 = new EdmProperty("B", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));
            PropertyMapping mapping = new ScalarPropertyMapping(property1, property2);

            Assert.Equal("ScalarProperty(Identity=A,ColumnIdentity=B)", 
                BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mapping));
        }
Ejemplo n.º 19
0
 protected virtual void Visit(ScalarPropertyMapping scalarPropertyMapping)
 {
     Visit(scalarPropertyMapping.Column);
     Visit(scalarPropertyMapping.Property);
 }
Ejemplo n.º 20
0
        public void Cannot_remove_property_when_read_only()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);

            mappingFragment.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => mappingFragment.RemovePropertyMapping(scalarPropertyMapping)).Message);
        }
Ejemplo n.º 21
0
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));
            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);
            mappingFragment.AddCondition(conditionMapping);

            Assert.False(scalarPropertyMapping.IsReadOnly);
            Assert.False(conditionMapping.IsReadOnly);
            mappingFragment.SetReadOnly();
            Assert.True(scalarPropertyMapping.IsReadOnly);
            Assert.True(conditionMapping.IsReadOnly);
        }
 internal void SetTarget(ScalarPropertyMapping scalarPropertyMapping)
 {
     this._scalarPropertyMapping = scalarPropertyMapping;
 }
        private string GetFullTypeName(ScalarPropertyMapping scalar)
        {
            if (scalar.Column.TypeName == "nvarchar" || scalar.Column.TypeName == "varchar")
            {
                return string.Format("{0}({1})", scalar.Column.TypeName, scalar.Column.MaxLength);
            }

            if (scalar.Column.TypeName == "decimal" || scalar.Column.TypeName == "numeric")
            {
                return string.Format("{0}({1},{2})", scalar.Column.TypeName, scalar.Column.Precision, scalar.Column.Scale);
            }

            return scalar.Column.TypeName;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Removes a child property-column mapping.
        /// </summary>
        /// <param name="propertyMapping">A ScalarPropertyMapping that specifies
        /// the property-column mapping to be removed.</param>
        public void RemovePropertyMapping(ScalarPropertyMapping propertyMapping)
        {
            Check.NotNull(propertyMapping, "propertyMapping");
            ThrowIfReadOnly();

            _properties.Remove(propertyMapping);
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var complexType = new ComplexType();
            var complexTypeMapping = new ComplexTypeMapping(complexType);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));
            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            complexTypeMapping.AddPropertyMapping(scalarPropertyMapping);
            complexTypeMapping.AddCondition(conditionMapping);

            Assert.False(scalarPropertyMapping.IsReadOnly);
            Assert.False(conditionMapping.IsReadOnly);
            complexTypeMapping.SetReadOnly();
            Assert.True(scalarPropertyMapping.IsReadOnly);
            Assert.True(conditionMapping.IsReadOnly);
        }
Ejemplo n.º 26
0
        internal void AddColumnMapping(ColumnMappingBuilder columnMappingBuilder)
        {
            Check.NotNull(columnMappingBuilder, "columnMappingBuilder");
            if (!columnMappingBuilder.PropertyPath.Any()
                || _columnMappings.Contains(columnMappingBuilder))
            {
                throw new ArgumentException(Strings.InvalidColumnBuilderArgument("columnBuilderMapping"));
            }

            DebugCheck.NotNull(columnMappingBuilder.ColumnProperty);

            _columnMappings.Add(columnMappingBuilder);

            StructuralTypeMapping structuralTypeMapping = this;
            EdmProperty property;

            // Turn the property path into a mapping fragment nested tree structure.

            var i = 0;
            for (; i < columnMappingBuilder.PropertyPath.Count - 1; i++)
            {
                // The first n-1 properties are complex so we just need to build
                // a corresponding tree of complex type mappings.

                property = columnMappingBuilder.PropertyPath[i];

                var complexPropertyMapping
                    = structuralTypeMapping
                        .PropertyMappings
                        .OfType<ComplexPropertyMapping>()
                        .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

                ComplexTypeMapping complexTypeMapping = null;

                if (complexPropertyMapping == null)
                {
                    complexTypeMapping = new ComplexTypeMapping(false);
                    complexTypeMapping.AddType(property.ComplexType);

                    complexPropertyMapping = new ComplexPropertyMapping(property);
                    complexPropertyMapping.AddTypeMapping(complexTypeMapping);

                    structuralTypeMapping.AddPropertyMapping(complexPropertyMapping);
                }

                structuralTypeMapping
                    = complexTypeMapping
                      ?? complexPropertyMapping.TypeMappings.Single();
            }

            // The last property has to be a scalar mapping to the target column.
            // Extract it and create the scalar mapping leaf node, ensuring that we 
            // set the target column.

            property = columnMappingBuilder.PropertyPath[i];

            var scalarPropertyMapping
                = structuralTypeMapping
                    .PropertyMappings
                    .OfType<ScalarPropertyMapping>()
                    .SingleOrDefault(pm => ReferenceEquals(pm.Property, property));

            if (scalarPropertyMapping == null)
            {
                scalarPropertyMapping
                    = new ScalarPropertyMapping(property, columnMappingBuilder.ColumnProperty);

                structuralTypeMapping.AddPropertyMapping(scalarPropertyMapping);

                columnMappingBuilder.SetTarget(scalarPropertyMapping);
            }
            else
            {
                scalarPropertyMapping.Column = columnMappingBuilder.ColumnProperty;
            }
        }
Ejemplo n.º 27
0
        private void WritePropertyMapping(ScalarPropertyMapping scalarPropertyMapping)
        {
            DebugCheck.NotNull(scalarPropertyMapping);

            WriteScalarPropertyElement(scalarPropertyMapping.Property.Name, scalarPropertyMapping.Column.Name);
        }
 internal void SetTarget(ScalarPropertyMapping scalarPropertyMapping)
 {
     _scalarPropertyMapping = scalarPropertyMapping;
 }
 /// <summary>Removes a child property-column mapping.</summary>
 /// <param name="propertyMapping">A ScalarPropertyMapping that specifies
 /// the property-column mapping to be removed.</param>
 public void RemovePropertyMapping(ScalarPropertyMapping propertyMapping)
 {
     Check.NotNull <ScalarPropertyMapping>(propertyMapping, nameof(propertyMapping));
     this.ThrowIfReadOnly();
     this._properties.Remove(propertyMapping);
 }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var associationEnd = new AssociationEndMember("E", new EntityType("E", "N", DataSpace.CSpace));
            var mapping = new EndPropertyMapping(associationEnd);
            var scalarPropertyMapping
                = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));
            mapping.AddPropertyMapping(scalarPropertyMapping);

            Assert.False(scalarPropertyMapping.IsReadOnly);
            mapping.SetReadOnly();
            Assert.True(scalarPropertyMapping.IsReadOnly);
        }