src/Shared/EntityFramework/Core/Query/PlanCompiler/ColumnMapProcessor.cs
// <summary>
// Creates a column map for a polymorphic type. This method first
// creates column maps for each type that is a subtype of the input type,
// and then creates a dictionary of typeid value -> column
// Finally, a PolymorphicColumnMap is created with these pieces of information
// </summary>
// <param name="typeInfo"> Info about the type </param>
// <param name="name"> column name </param>
Creates a column map for a polymorphic type. This method first
creates column maps for each type that is a subtype of the input type,
and then creates a dictionary of typeid value -> column
Finally, a PolymorphicColumnMap is created with these pieces of information
Creates a column map for a polymorphic type . This method first creates column maps for each type that is a subtype of the input type and then creates a dictionary of typeid value - > column Finally a PolymorphicColumnMap is created with these pieces of information
[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 SimplePolymorphicColumnMap CreatePolymorphicColumnMap(TypeInfo typeInfo, string name)
        {
            var discriminatorMap = new Dictionary<object, TypedColumnMap>(
                typeInfo.RootType.DiscriminatorMap == null ? null : TrailingSpaceComparer.Instance);
            var allMaps = new List<TypedColumnMap>();
            TypeInfo rootTypeInfo = typeInfo.RootType;
            var typeIdColumnMap = CreateTypeIdColumnMap(rootTypeInfo.TypeIdProperty);
            if (md.TypeSemantics.IsComplexType(typeInfo.Type))
            {
                CreateComplexTypeColumnMap(rootTypeInfo, name, null, discriminatorMap, allMaps);
            }
            else
            {
                CreateEntityColumnMap(rootTypeInfo, name, null, discriminatorMap, allMaps, true);
            }
            TypedColumnMap baseTypeColumnMap = null;
            foreach (var value in allMaps)
            {
                if (md.TypeSemantics.IsStructurallyEqual(value.Type, typeInfo.Type))
                {
                    baseTypeColumnMap = value;
                    break;
                }
            }
            PlanCompiler.Assert(null != baseTypeColumnMap, "Didn't find requested type in polymorphic type hierarchy?");
            var result = new SimplePolymorphicColumnMap(
                typeInfo.Type, name, baseTypeColumnMap.Properties, typeIdColumnMap, discriminatorMap);
            return result;
        }
[ SuppressMessage ( " " , " " , MessageId = " " ) ] private SimplePolymorphicColumnMap CreatePolymorphicColumnMap ( TypeInfo typeInfo , string name ) { var discriminatorMap = new Dictionary < object , TypedColumnMap > ( typeInfo . RootType . DiscriminatorMap == null ? null : TrailingSpaceComparer . Instance ) ; var allMaps = new List < TypedColumnMap > ( ) ; TypeInfo rootTypeInfo = typeInfo . RootType ; var typeIdColumnMap = CreateTypeIdColumnMap ( rootTypeInfo . TypeIdProperty ) ; if ( md . TypeSemantics . IsComplexType ( typeInfo . Type ) ) { CreateComplexTypeColumnMap ( rootTypeInfo , name , null , discriminatorMap , allMaps ) ; } else { CreateEntityColumnMap ( rootTypeInfo , name , null , discriminatorMap , allMaps , true ) ; } TypedColumnMap baseTypeColumnMap = null ; foreach ( var value in allMaps ) { if ( md . TypeSemantics . IsStructurallyEqual ( value . Type , typeInfo . Type ) ) { baseTypeColumnMap = value ; break ; } } PlanCompiler . Assert ( null != baseTypeColumnMap , " " ) ; var result = new SimplePolymorphicColumnMap ( typeInfo . Type , name , baseTypeColumnMap . Properties , typeIdColumnMap , discriminatorMap ) ; return result ; }
Creates a column map for a polymorphic type.
Creates a column map for a polymorphic type .
// if the typeInfo has a DiscriminatorMap, use TrailingSpaceComparer to ensure that lookups // against discriminator values that SQL Server has right-padded (e.g. nchar and char) are properly // interpreted // abstract types may not have discriminator values, but may nonetheless be interesting // SQLBUDT #433011 -- Polymorphic types must construct column maps //                    that map to the entire type hierarchy, so we //                    need to use the RootType, not the current type. // Get the type discriminant column first // process complex/entity types appropriately // use the same name for the column  // Naturally, nothing is simple; we need to walk the rootTypeColumnMap hierarchy // and find the column map for the type that we are supposed to have as the base // type of this hierarchy. // Create a polymorphic column map
typeInfo
TypeInfo
Info about the type
Info about the type
name
string
None