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; } }