public void SetReadOnly_is_called_on_child_mapping_items() { var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null); var property = EdmProperty.CreateComplex("P", complexType); var mapping = new ComplexPropertyMapping(property); var typeMapping = new ComplexTypeMapping(isPartial: false); mapping.AddTypeMapping(typeMapping); Assert.False(typeMapping.IsReadOnly); mapping.SetReadOnly(); Assert.True(typeMapping.IsReadOnly); }
public void Cannot_add_type_mapping_when_read_only() { var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null); var property = EdmProperty.CreateComplex("P", complexType); var mapping = new ComplexPropertyMapping(property); mapping.SetReadOnly(); Assert.True(mapping.IsReadOnly); var typeMapping = new ComplexTypeMapping(isPartial: false); Assert.Equal( Strings.OperationOnReadOnlyItem, Assert.Throws<InvalidOperationException>( () => mapping.AddTypeMapping(typeMapping)).Message); }
public void Cannot_add_type_mapping_when_read_only() { var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null); var property = EdmProperty.CreateComplex("P", complexType); var mapping = new ComplexPropertyMapping(property); mapping.SetReadOnly(); Assert.True(mapping.IsReadOnly); var typeMapping = new ComplexTypeMapping(isPartial: false); Assert.Equal( Strings.OperationOnReadOnlyItem, Assert.Throws <InvalidOperationException>( () => mapping.AddTypeMapping(typeMapping)).Message); }
public void Can_add_get_remove_type_mappings() { var complexType = ComplexType.Create("CT", "NS", DataSpace.CSpace, new EdmMember[0], null); var property = EdmProperty.CreateComplex("P", complexType); var mapping = new ComplexPropertyMapping(property); Assert.Equal(0, mapping.TypeMappings.Count); var typeMapping = new ComplexTypeMapping(isPartial: false); mapping.AddTypeMapping(typeMapping); Assert.Equal(1, mapping.TypeMappings.Count); Assert.Same(typeMapping, mapping.TypeMappings[0]); mapping.RemoveTypeMapping(typeMapping); Assert.Equal(0, mapping.TypeMappings.Count); }
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; } }
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; } }
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; } }