internal override void Visit(EntityColumnMap columnMap, int dummy) { Append("E-", columnMap.Type); Append(",N", columnMap.NullSentinel); Append(",P", columnMap.Properties); Append(",I", columnMap.EntityIdentity); }
private SimpleCollectionColumnMap BuildSimpleEntitySetColumnMap(Mock <MetadataWorkspace> metadataWorkspaceMock, CodeFirstOSpaceTypeFactory codeFirstOSpaceTypeFactory = null) { var cSpaceEntityType = new EntityType(typeof(SimpleEntity).Name, "N", DataSpace.CSpace); var intTypeUsage = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), new FacetValues { Nullable = false }); cSpaceEntityType.AddMember(new EdmProperty("Id", intTypeUsage)); cSpaceEntityType.AddMember(new EdmProperty("Count", intTypeUsage)); var entityTypeUsage = TypeUsage.Create(cSpaceEntityType); var idScalarMap = new ScalarColumnMap(intTypeUsage, "Id", 0, 0); var entityMap = new EntityColumnMap( entityTypeUsage, "E", new[] { idScalarMap, new ScalarColumnMap(intTypeUsage, "Count", 0, 1) }, new SimpleEntityIdentity(null, new SimpleColumnMap[] { idScalarMap })); var collectionMap = new SimpleCollectionColumnMap( entityTypeUsage, "MockCollectionType", entityMap, null, null); codeFirstOSpaceTypeFactory = codeFirstOSpaceTypeFactory ?? new CodeFirstOSpaceTypeFactory(); var oSpaceEntityType = codeFirstOSpaceTypeFactory.TryCreateType(typeof(SimpleEntity), cSpaceEntityType); codeFirstOSpaceTypeFactory.CspaceToOspace.Add(cSpaceEntityType, oSpaceEntityType); metadataWorkspaceMock.Setup(m => m.GetItem <EdmType>("N.SimpleEntity", DataSpace.OSpace)) .Returns(oSpaceEntityType); return(collectionMap); }
internal override void Visit(EntityColumnMap columnMap, int dummy) { this.Append("E-", columnMap.Type); this.Append(",N", (ColumnMap)columnMap.NullSentinel); this.Append(",P", (IEnumerable <ColumnMap>)columnMap.Properties); this.Append(",I", columnMap.EntityIdentity); }
internal virtual void Visit(EntityColumnMap columnMap, TArgType arg) { VisitEntityIdentity(columnMap.EntityIdentity, arg); foreach (var p in columnMap.Properties) { p.Accept(this, arg); } }
internal virtual void Visit(EntityColumnMap columnMap, TArgType arg) { this.VisitEntityIdentity(columnMap.EntityIdentity, arg); foreach (ColumnMap property in columnMap.Properties) { property.Accept <TArgType>(this, arg); } }
/// <summary> /// EntityColumnMap /// </summary> /// <param name="columnMap"></param> /// <param name="translationDelegate"></param> /// <returns></returns> internal override ColumnMap Visit(EntityColumnMap columnMap, ColumnMapTranslatorTranslationDelegate translationDelegate) { EntityIdentity newEntityIdentity = VisitEntityIdentity(columnMap.EntityIdentity, translationDelegate); VisitList(columnMap.Properties, translationDelegate); if (newEntityIdentity != columnMap.EntityIdentity) { columnMap = new EntityColumnMap(columnMap.Type, columnMap.Name, columnMap.Properties, newEntityIdentity); } return(translationDelegate(columnMap)); }
internal override ColumnMap Visit( EntityColumnMap columnMap, ColumnMapTranslatorTranslationDelegate translationDelegate) { EntityIdentity entityIdentity = this.VisitEntityIdentity(columnMap.EntityIdentity, translationDelegate); this.VisitList <ColumnMap>(columnMap.Properties, translationDelegate); if (entityIdentity != columnMap.EntityIdentity) { columnMap = new EntityColumnMap(columnMap.Type, columnMap.Name, columnMap.Properties, entityIdentity); } return(translationDelegate((ColumnMap)columnMap)); }
/// <summary> /// Create a column map for an entitytype column. /// Currently, the key columns are not duplicated (ie) they point into the /// same locations as in the properties list. /// Note: we also don't handle keys that are properties of nested fields /// </summary> /// <param name="typeInfo">Type information for the type</param> /// <param name="name">column name</param> /// <param name="superTypeColumnMap">supertype information if any</param> /// <param name="discriminatorMap">Dictionary of typeid->column map information</param> /// <param name="allMaps">List of all column maps (including those without typeid)</param> /// <param name="handleRelProperties">should we handle rel-properties?</param> /// <returns></returns> private EntityColumnMap CreateEntityColumnMap(TypeInfo typeInfo, string name, EntityColumnMap superTypeColumnMap, Dictionary<object, TypedColumnMap> discriminatorMap, List<TypedColumnMap> allMaps, bool handleRelProperties) { EntityColumnMap columnMap = null; List<ColumnMap> propertyColumnMapList = new List<ColumnMap>(); // Copy over information from my supertype if it already exists if (superTypeColumnMap != null) { // get supertype properties foreach (ColumnMap c in superTypeColumnMap.Properties) { propertyColumnMapList.Add(c); } // Now add on all of my "specific" properties foreach (md.EdmMember property in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type)) { ColumnMap propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name); propertyColumnMapList.Add(propertyColumnMap); } // create the entity column map w/ information from my supertype columnMap = new EntityColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), superTypeColumnMap.EntityIdentity); } else { SimpleColumnMap entitySetIdColumnMap = null; if (typeInfo.HasEntitySetIdProperty) { entitySetIdColumnMap = CreateEntitySetIdColumnMap(typeInfo.EntitySetIdProperty); } // build up a list of key columns List<SimpleColumnMap> keyColumnMapList = new List<SimpleColumnMap>(); // Create a dictionary to look up the key properties Dictionary<md.EdmProperty, ColumnMap> keyPropertyMap = new Dictionary<md.EdmProperty, ColumnMap>(); foreach (md.EdmMember property in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type)) { ColumnMap propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name); propertyColumnMapList.Add(propertyColumnMap); // add property to keymap, if this property is part of the key if (md.TypeSemantics.IsPartOfKey(property)) { md.EdmProperty edmProperty = property as md.EdmProperty; PlanCompiler.Assert(edmProperty != null, "EntityType key member is not property?"); keyPropertyMap[edmProperty] = propertyColumnMap; } } // Build up the key list if required foreach (md.EdmMember keyProperty in TypeHelpers.GetEdmType<md.EntityType>(typeInfo.Type).KeyMembers) { md.EdmProperty edmKeyProperty = keyProperty as md.EdmProperty; PlanCompiler.Assert(edmKeyProperty != null, "EntityType key member is not property?"); SimpleColumnMap keyColumnMap = keyPropertyMap[edmKeyProperty] as SimpleColumnMap; PlanCompiler.Assert(keyColumnMap != null, "keyColumnMap is null"); keyColumnMapList.Add(keyColumnMap); } // // Create the entity identity. // EntityIdentity identity = CreateEntityIdentity((md.EntityType)typeInfo.Type.EdmType, entitySetIdColumnMap, keyColumnMapList.ToArray()); // finally create the entity column map columnMap = new EntityColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), identity); } // if a dictionary is supplied, add myself to the dictionary (abstract types need not be added) if (discriminatorMap != null) { // where DiscriminatedNewInstanceOp is used, there will not be an explicit type id for an abstract type // or types that do not appear in the QueryView // (the mapping will not include such information) if (null != typeInfo.TypeId) { discriminatorMap[typeInfo.TypeId] = columnMap; } } if (allMaps != null) { allMaps.Add(columnMap); } // Finally walk through my subtypes foreach (TypeInfo subTypeInfo in typeInfo.ImmediateSubTypes) { CreateEntityColumnMap(subTypeInfo, name, columnMap, discriminatorMap, allMaps, false); } // // Build up the list of rel property column maps // if (handleRelProperties) { BuildRelPropertyColumnMaps(typeInfo, true); } return columnMap; }
public void TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_entity_types() { var metadataWorkspaceMock = new Mock <MetadataWorkspace>(); metadataWorkspaceMock.Setup(m => m.GetQueryCacheManager()).Returns(QueryCacheManager.Create()); var cSpaceEntityType = new EntityType(typeof(ManyTypesEntity).Name, "N", DataSpace.CSpace); cSpaceEntityType.AddMember( new EdmProperty("P1Bool", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Boolean), new FacetValues { Nullable = false }))); cSpaceEntityType.AddMember( new EdmProperty("P2NullableBool", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Boolean), new FacetValues { Nullable = true }))); cSpaceEntityType.AddMember( new EdmProperty("P3ByteArray", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Binary)))); cSpaceEntityType.AddMember( new EdmProperty("P4Timespan", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Time), new FacetValues { Nullable = false }))); cSpaceEntityType.AddMember( new EdmProperty("P5NullableTimespan", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Time), new FacetValues { Nullable = true }))); var enumType = new EnumType( "DayOfWeek", "N", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), false, DataSpace.CSpace); cSpaceEntityType.AddMember( new EdmProperty("P6Enum", TypeUsage.Create(enumType, new FacetValues { Nullable = false }))); cSpaceEntityType.AddMember( new EdmProperty("P7NullableEnum", TypeUsage.Create(enumType, new FacetValues { Nullable = true }))); var entityTypeUsage = TypeUsage.Create(cSpaceEntityType); cSpaceEntityType.AddMember( new EdmProperty("P8Geography", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Geography)))); var oSpaceTypeFactory = new CodeFirstOSpaceTypeFactory(); var oSpaceEntityType = oSpaceTypeFactory.TryCreateType(typeof(ManyTypesEntity), cSpaceEntityType); oSpaceTypeFactory.CspaceToOspace.Add(enumType, oSpaceTypeFactory.TryCreateType(typeof(DayOfWeek), enumType)); foreach (var resolve in oSpaceTypeFactory.ReferenceResolutions) { resolve(); } var scalarMaps = new List <ScalarColumnMap>(); foreach (var edmProperty in cSpaceEntityType.Properties) { scalarMaps.Add(new ScalarColumnMap(edmProperty.TypeUsage, edmProperty.Name, 0, scalarMaps.Count)); } var entityMap = new EntityColumnMap( entityTypeUsage, "E", scalarMaps.ToArray(), new SimpleEntityIdentity(null, new SimpleColumnMap[] { scalarMaps[0] })); var collectionMap = new SimpleCollectionColumnMap( entityTypeUsage, "MockCollectionType", entityMap, null, null); metadataWorkspaceMock.Setup(m => m.GetItem <EdmType>(It.IsAny <string>(), DataSpace.OSpace)) .Returns(oSpaceEntityType); var factory = new Translator().TranslateColumnMap <object>( collectionMap, metadataWorkspaceMock.Object, new SpanIndex(), MergeOption.NoTracking, streaming: false, valueLayer: false); Assert.NotNull(factory); Assert.Equal( new[] { typeof(bool), typeof(bool), typeof(byte[]), typeof(TimeSpan), typeof(TimeSpan), typeof(int), typeof(int), typeof(DbGeography) }, factory.ColumnTypes); // The first column is nullable as it's part of the key Assert.Equal(new[] { true, true, true, false, true, false, true, true }, factory.NullableColumns); }
internal abstract TResultType Visit(EntityColumnMap columnMap, TArgType arg);
public void TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_entity_types() { var metadataWorkspaceMock = new Mock<MetadataWorkspace>(); metadataWorkspaceMock.Setup(m => m.GetQueryCacheManager()).Returns(QueryCacheManager.Create()); var cSpaceEntityType = new EntityType(typeof(ManyTypesEntity).Name, "N", DataSpace.CSpace); cSpaceEntityType.AddMember( new EdmProperty("P1Bool", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Boolean), new FacetValues { Nullable = false }))); cSpaceEntityType.AddMember( new EdmProperty("P2NullableBool", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Boolean), new FacetValues { Nullable = true }))); cSpaceEntityType.AddMember( new EdmProperty("P3ByteArray", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Binary)))); cSpaceEntityType.AddMember( new EdmProperty("P4Timespan", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Time), new FacetValues { Nullable = false }))); cSpaceEntityType.AddMember( new EdmProperty("P5NullableTimespan", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Time), new FacetValues { Nullable = true }))); var enumType = new EnumType( "DayOfWeek", "N", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), false, DataSpace.CSpace); cSpaceEntityType.AddMember( new EdmProperty("P6Enum", TypeUsage.Create(enumType, new FacetValues { Nullable = false }))); cSpaceEntityType.AddMember( new EdmProperty("P7NullableEnum", TypeUsage.Create(enumType, new FacetValues { Nullable = true }))); var entityTypeUsage = TypeUsage.Create(cSpaceEntityType); cSpaceEntityType.AddMember( new EdmProperty("P8Geography", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Geography)))); var oSpaceTypeFactory = new CodeFirstOSpaceTypeFactory(); var oSpaceEntityType = oSpaceTypeFactory.TryCreateType(typeof(ManyTypesEntity), cSpaceEntityType); oSpaceTypeFactory.CspaceToOspace.Add(enumType, oSpaceTypeFactory.TryCreateType(typeof(DayOfWeek), enumType)); foreach (var resolve in oSpaceTypeFactory.ReferenceResolutions) { resolve(); } var scalarMaps = new List<ScalarColumnMap>(); foreach (var edmProperty in cSpaceEntityType.Properties) { scalarMaps.Add(new ScalarColumnMap(edmProperty.TypeUsage, edmProperty.Name, 0, scalarMaps.Count)); } var entityMap = new EntityColumnMap( entityTypeUsage, "E", scalarMaps.ToArray(), new SimpleEntityIdentity(null, new SimpleColumnMap[] { scalarMaps[0] })); var collectionMap = new SimpleCollectionColumnMap( entityTypeUsage, "MockCollectionType", entityMap, null, null); metadataWorkspaceMock.Setup(m => m.GetItem<EdmType>(It.IsAny<string>(), DataSpace.OSpace)) .Returns(oSpaceEntityType); var factory = new Translator().TranslateColumnMap<object>( collectionMap, metadataWorkspaceMock.Object, new SpanIndex(), MergeOption.NoTracking, streaming: false, valueLayer: false); Assert.NotNull(factory); Assert.Equal( new[] { typeof(bool), typeof(bool), typeof(byte[]), typeof(TimeSpan), typeof(TimeSpan), typeof(int), typeof(int), typeof(DbGeography) }, factory.ColumnTypes); // The first column is nullable as it's part of the key Assert.Equal(new[] { true, true, true, false, true, false, true, true }, factory.NullableColumns); }
private SimpleCollectionColumnMap BuildSimpleEntitySetColumnMap(Mock<MetadataWorkspace> metadataWorkspaceMock, CodeFirstOSpaceTypeFactory codeFirstOSpaceTypeFactory = null) { var cSpaceEntityType = new EntityType(typeof(SimpleEntity).Name, "N", DataSpace.CSpace); var intTypeUsage = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), new FacetValues{Nullable = false}); cSpaceEntityType.AddMember(new EdmProperty("Id", intTypeUsage)); cSpaceEntityType.AddMember(new EdmProperty("Count", intTypeUsage)); var entityTypeUsage = TypeUsage.Create(cSpaceEntityType); var idScalarMap = new ScalarColumnMap(intTypeUsage, "Id", 0, 0); var entityMap = new EntityColumnMap( entityTypeUsage, "E", new[] { idScalarMap, new ScalarColumnMap(intTypeUsage, "Count", 0, 1)}, new SimpleEntityIdentity(null, new SimpleColumnMap[] { idScalarMap })); var collectionMap = new SimpleCollectionColumnMap( entityTypeUsage, "MockCollectionType", entityMap, null, null); codeFirstOSpaceTypeFactory = codeFirstOSpaceTypeFactory ?? new CodeFirstOSpaceTypeFactory(); var oSpaceEntityType = codeFirstOSpaceTypeFactory.TryCreateType(typeof(SimpleEntity), cSpaceEntityType); codeFirstOSpaceTypeFactory.CspaceToOspace.Add(cSpaceEntityType, oSpaceEntityType); metadataWorkspaceMock.Setup(m => m.GetItem<EdmType>("N.SimpleEntity", DataSpace.OSpace)) .Returns(oSpaceEntityType); return collectionMap; }
private EntityColumnMap CreateEntityColumnMap( TypeInfo typeInfo, string name, EntityColumnMap superTypeColumnMap, Dictionary <object, TypedColumnMap> discriminatorMap, List <TypedColumnMap> allMaps, bool handleRelProperties) { EntityColumnMap columnMap = null; var propertyColumnMapList = new List <ColumnMap>(); // Copy over information from my supertype if it already exists if (superTypeColumnMap != null) { // get supertype properties foreach (var c in superTypeColumnMap.Properties) { propertyColumnMapList.Add(c); } // Now add on all of my "specific" properties foreach (md.EdmMember property in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type)) { var propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name); propertyColumnMapList.Add(propertyColumnMap); } // create the entity column map w/ information from my supertype columnMap = new EntityColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), superTypeColumnMap.EntityIdentity); } else { SimpleColumnMap entitySetIdColumnMap = null; if (typeInfo.HasEntitySetIdProperty) { entitySetIdColumnMap = CreateEntitySetIdColumnMap(typeInfo.EntitySetIdProperty); } // build up a list of key columns var keyColumnMapList = new List <SimpleColumnMap>(); // Create a dictionary to look up the key properties var keyPropertyMap = new Dictionary <md.EdmProperty, ColumnMap>(); foreach (md.EdmMember property in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type)) { var propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name); propertyColumnMapList.Add(propertyColumnMap); // add property to keymap, if this property is part of the key if (md.TypeSemantics.IsPartOfKey(property)) { var edmProperty = property as md.EdmProperty; PlanCompiler.Assert(edmProperty != null, "EntityType key member is not property?"); keyPropertyMap[edmProperty] = propertyColumnMap; } } // Build up the key list if required foreach (var keyProperty in TypeHelpers.GetEdmType <md.EntityType>(typeInfo.Type).KeyMembers) { var edmKeyProperty = keyProperty as md.EdmProperty; PlanCompiler.Assert(edmKeyProperty != null, "EntityType key member is not property?"); var keyColumnMap = keyPropertyMap[edmKeyProperty] as SimpleColumnMap; PlanCompiler.Assert(keyColumnMap != null, "keyColumnMap is null"); keyColumnMapList.Add(keyColumnMap); } // // Create the entity identity. // var identity = CreateEntityIdentity((md.EntityType)typeInfo.Type.EdmType, entitySetIdColumnMap, keyColumnMapList.ToArray()); // finally create the entity column map columnMap = new EntityColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), identity); } // if a dictionary is supplied, add myself to the dictionary (abstract types need not be added) if (discriminatorMap != null) { // where DiscriminatedNewInstanceOp is used, there will not be an explicit type id for an abstract type // or types that do not appear in the QueryView // (the mapping will not include such information) if (null != typeInfo.TypeId) { discriminatorMap[typeInfo.TypeId] = columnMap; } } if (allMaps != null) { allMaps.Add(columnMap); } // Finally walk through my subtypes foreach (var subTypeInfo in typeInfo.ImmediateSubTypes) { CreateEntityColumnMap(subTypeInfo, name, columnMap, discriminatorMap, allMaps, false); } // // Build up the list of rel property column maps // if (handleRelProperties) { BuildRelPropertyColumnMaps(typeInfo, true); } return(columnMap); }
private EntityColumnMap CreateEntityColumnMap( TypeInfo typeInfo, string name, EntityColumnMap superTypeColumnMap, Dictionary <object, TypedColumnMap> discriminatorMap, List <TypedColumnMap> allMaps, bool handleRelProperties) { List <ColumnMap> columnMapList = new List <ColumnMap>(); EntityColumnMap superTypeColumnMap1; if (superTypeColumnMap != null) { foreach (ColumnMap property in superTypeColumnMap.Properties) { columnMapList.Add(property); } foreach (EdmMember structuralMember in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type)) { ColumnMap columnMap = this.CreateColumnMap(Helper.GetModelTypeUsage(structuralMember), structuralMember.Name); columnMapList.Add(columnMap); } superTypeColumnMap1 = new EntityColumnMap(typeInfo.Type, name, columnMapList.ToArray(), superTypeColumnMap.EntityIdentity); } else { SimpleColumnMap entitySetIdColumnMap = (SimpleColumnMap)null; if (typeInfo.HasEntitySetIdProperty) { entitySetIdColumnMap = this.CreateEntitySetIdColumnMap(typeInfo.EntitySetIdProperty); } List <SimpleColumnMap> simpleColumnMapList = new List <SimpleColumnMap>(); Dictionary <EdmProperty, ColumnMap> dictionary = new Dictionary <EdmProperty, ColumnMap>(); foreach (EdmMember structuralMember in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type)) { ColumnMap columnMap = this.CreateColumnMap(Helper.GetModelTypeUsage(structuralMember), structuralMember.Name); columnMapList.Add(columnMap); if (TypeSemantics.IsPartOfKey(structuralMember)) { EdmProperty index = structuralMember as EdmProperty; System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(index != null, "EntityType key member is not property?"); dictionary[index] = columnMap; } } foreach (EdmMember keyMember in TypeHelpers.GetEdmType <EntityType>(typeInfo.Type).KeyMembers) { EdmProperty index = keyMember as EdmProperty; System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(index != null, "EntityType key member is not property?"); SimpleColumnMap simpleColumnMap = dictionary[index] as SimpleColumnMap; System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(simpleColumnMap != null, "keyColumnMap is null"); simpleColumnMapList.Add(simpleColumnMap); } EntityIdentity entityIdentity = this.CreateEntityIdentity((EntityType)typeInfo.Type.EdmType, entitySetIdColumnMap, simpleColumnMapList.ToArray()); superTypeColumnMap1 = new EntityColumnMap(typeInfo.Type, name, columnMapList.ToArray(), entityIdentity); } if (discriminatorMap != null && typeInfo.TypeId != null) { discriminatorMap[typeInfo.TypeId] = (TypedColumnMap)superTypeColumnMap1; } allMaps?.Add((TypedColumnMap)superTypeColumnMap1); foreach (TypeInfo immediateSubType in typeInfo.ImmediateSubTypes) { this.CreateEntityColumnMap(immediateSubType, name, superTypeColumnMap1, discriminatorMap, allMaps, false); } if (handleRelProperties) { this.BuildRelPropertyColumnMaps(typeInfo, true); } return(superTypeColumnMap1); }
/// <summary> /// Build the entityColumnMap from a store datareader, a type and an entitySet and /// a list ofproperties. /// </summary> /// <param name="storeDataReader"></param> /// <param name="edmType"></param> /// <param name="entitySet"></param> /// <param name="propertyColumnMaps"></param> /// <returns></returns> private static EntityColumnMap CreateEntityTypeElementColumnMap( DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, ColumnMap[] propertyColumnMaps, Dictionary<string, FunctionImportReturnTypeStructuralTypeColumnRenameMapping> renameList) { EntityType entityType = (EntityType)edmType; // The tricky part here is // that the KeyColumns list must point at the same ColumnMap(s) that // the properties list points to, so we build a quick array of // ColumnMap(s) that are indexed by their ordinal; then we can walk // the list of keyMembers, and find the ordinal in the reader, and // pick the same ColumnMap for it. // Build the ordinal -> ColumnMap index ColumnMap[] ordinalToColumnMap = new ColumnMap[storeDataReader.FieldCount]; foreach (ColumnMap propertyColumnMap in propertyColumnMaps) { int ordinal = ((ScalarColumnMap)propertyColumnMap).ColumnPos; ordinalToColumnMap[ordinal] = propertyColumnMap; } // Now build the list of KeyColumns; IList<EdmMember> keyMembers = entityType.KeyMembers; SimpleColumnMap[] keyColumns = new SimpleColumnMap[keyMembers.Count]; int keyMemberIndex = 0; foreach (EdmMember keyMember in keyMembers) { int keyOrdinal = GetMemberOrdinalFromReader(storeDataReader, keyMember, edmType, renameList); Debug.Assert(keyOrdinal >= 0, "keyMember for entity is not found by name in the data reader?"); ColumnMap keyColumnMap = ordinalToColumnMap[keyOrdinal]; Debug.Assert(null != keyColumnMap, "keyMember for entity isn't in properties collection for the entity?"); keyColumns[keyMemberIndex] = (SimpleColumnMap)keyColumnMap; keyMemberIndex++; } SimpleEntityIdentity entityIdentity = new SimpleEntityIdentity(entitySet, keyColumns); EntityColumnMap result = new EntityColumnMap(TypeUsage.Create(edmType), edmType.Name, propertyColumnMaps, entityIdentity); return result; }