src/Shared/EntityFramework/Core/Query/PlanCompiler/ColumnMapProcessor.cs
// <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>
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
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
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "keyColumnMap")]
        [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "EntityType")]
        [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters",
            MessageId = "System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(System.Boolean,System.String)")]
        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>();
            if (superTypeColumnMap != null)
            {
                foreach (var c in superTypeColumnMap.Properties)
                {
                    propertyColumnMapList.Add(c);
                }
                foreach (md.EdmMember property in TypeHelpers.GetDeclaredStructuralMembers(typeInfo.Type))
                {
                    var propertyColumnMap = CreateColumnMap(md.Helper.GetModelTypeUsage(property), property.Name);
                    propertyColumnMapList.Add(propertyColumnMap);
                }
                columnMap = new EntityColumnMap(typeInfo.Type, name, propertyColumnMapList.ToArray(), superTypeColumnMap.EntityIdentity);
            }
            else
            {
                SimpleColumnMap entitySetIdColumnMap = null;
                if (typeInfo.HasEntitySetIdProperty)
                {
                    entitySetIdColumnMap = CreateEntitySetIdColumnMap(typeInfo.EntitySetIdProperty);
                }
                var keyColumnMapList = new List<SimpleColumnMap>();
                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);
                    if (md.TypeSemantics.IsPartOfKey(property))
                    {
                        var edmProperty = property as md.EdmProperty;
                        PlanCompiler.Assert(edmProperty != null, "EntityType key member is not property?");
                        keyPropertyMap[edmProperty] = propertyColumnMap;
                    }
                }
                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;
        }
[ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] 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 > ( ) ; if ( superTypeColumnMap != null ) { foreach ( var c in superTypeColumnMap . Properties ) { propertyColumnMapList . Add ( c ) ; } foreach ( md . EdmMember property in TypeHelpers . GetDeclaredStructuralMembers ( typeInfo . Type ) ) { var propertyColumnMap = CreateColumnMap ( md . Helper . GetModelTypeUsage ( property ) , property . Name ) ; propertyColumnMapList . Add ( propertyColumnMap ) ; } columnMap = new EntityColumnMap ( typeInfo . Type , name , propertyColumnMapList . ToArray ( ) , superTypeColumnMap . EntityIdentity ) ; } else { SimpleColumnMap entitySetIdColumnMap = null ; if ( typeInfo . HasEntitySetIdProperty ) { entitySetIdColumnMap = CreateEntitySetIdColumnMap ( typeInfo . EntitySetIdProperty ) ; } var keyColumnMapList = new List < SimpleColumnMap > ( ) ; 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 ) ; if ( md . TypeSemantics . IsPartOfKey ( property ) ) { var edmProperty = property as md . EdmProperty ; PlanCompiler . Assert ( edmProperty != null , " " ) ; keyPropertyMap [ edmProperty ] = propertyColumnMap ; } } foreach ( var keyProperty in TypeHelpers . GetEdmType < md . EntityType > ( typeInfo . Type ) . KeyMembers ) { var edmKeyProperty = keyProperty as md . EdmProperty ; PlanCompiler . Assert ( edmKeyProperty != null , " " ) ; var keyColumnMap = keyPropertyMap [ edmKeyProperty ] as SimpleColumnMap ; PlanCompiler . Assert ( keyColumnMap != null , " " ) ; keyColumnMapList . Add ( keyColumnMap ) ; } var identity = CreateEntityIdentity ( ( md . EntityType ) typeInfo . Type . EdmType , entitySetIdColumnMap , keyColumnMapList . ToArray ( ) ) ; columnMap = new EntityColumnMap ( typeInfo . Type , name , propertyColumnMapList . ToArray ( ) , identity ) ; } if ( discriminatorMap != null ) { if ( null != typeInfo . TypeId ) { discriminatorMap [ typeInfo . TypeId ] = columnMap ; } } if ( allMaps != null ) { allMaps . Add ( columnMap ) ; } foreach ( var subTypeInfo in typeInfo . ImmediateSubTypes ) { CreateEntityColumnMap ( subTypeInfo , name , columnMap , discriminatorMap , allMaps , false ) ; } if ( handleRelProperties ) { BuildRelPropertyColumnMaps ( typeInfo , true ) ; } return columnMap ; }
Create a column map for an entitytype column.
Create a column map for an entitytype column .
// Copy over information from my supertype if it already exists // get supertype properties // Now add on all of my "specific" properties // create the entity column map w/ information from my supertype // build up a list of key columns // Create a dictionary to look up the key properties // add property to keymap, if this property is part of the key // Build up the key list if required // // Create the entity identity.  // // finally create the entity column map // if a dictionary is supplied, add myself to the dictionary (abstract types need not be added) // 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) // Finally walk through my subtypes // // Build up the list of rel property column maps //
typeInfo
TypeInfo
Type information for the type
Type information for the type
name
string
None
superTypeColumnMap
EntityColumnMap
supertype information if any
supertype information if any
discriminatorMap
Dictionary<object, TypedColumnMap>
Dictionary of typeid->column map information
Dictionary of typeid - > column map information
allMaps
List<TypedColumnMap>
List of all column maps (including those without typeid)
List of all column maps ( including those without typeid )
handleRelProperties
bool
None