src/Shared/EntityFramework/Core/Mapping/FunctionImportMappingNonComposable.cs
// <summary>
// Determines the expected shape of store results. We expect a column for every property
// of the mapped type (or types) and a column for every discriminator column. We make no
// assumptions about the order of columns: the provider is expected to determine appropriate
// types by looking at the names of the result columns, not the order of columns, which is
// different from the typical handling of row types in the EF.
// </summary>
// <remarks>
// Requires that the given function import mapping refers to a Collection(Entity) or Collection(ComplexType) CSDL
// function.
// </remarks>
// <returns> Row type. </returns>
Determines the expected shape of store results. We expect a column for every property
of the mapped type (or types) and a column for every discriminator column. We make no
assumptions about the order of columns: the provider is expected to determine appropriate
types by looking at the names of the result columns, not the order of columns, which is
different from the typical handling of row types in the EF.
Determines the expected shape of store results . We expect a column for every property of the mapped type ( or types ) and a column for every discriminator column . We make no assumptions about the order of columns : the provider is expected to determine appropriate types by looking at the names of the result columns not the order of columns which is different from the typical handling of row types in the EF .
internal TypeUsage GetExpectedTargetResultType(int resultSetIndex)
        {
            var resultMapping = GetResultMapping(resultSetIndex);
            var columns = new Dictionary<string, TypeUsage>();
            IEnumerable<StructuralType> structuralTypes;
            if (0 == resultMapping.NormalizedEntityTypeMappings.Count)
            {
                StructuralType structuralType;
                MetadataHelper.TryGetFunctionImportReturnType(FunctionImport, resultSetIndex, out structuralType);
                Debug.Assert(null != structuralType, "this method must be called only for entity/complextype reader function imports");
                structuralTypes = new[] { structuralType };
            }
            else
            {
                structuralTypes = resultMapping.MappedEntityTypes.Cast<StructuralType>();
            }
            foreach (var structuralType in structuralTypes)
            {
                foreach (EdmProperty property in TypeHelpers.GetAllStructuralMembers(structuralType))
                {
                    columns[property.Name] = property.TypeUsage;
                }
            }
            foreach (var discriminatorColumn in GetDiscriminatorColumns(resultSetIndex))
            {
                if (!columns.ContainsKey(discriminatorColumn))
                {
                    var type = TypeUsage.CreateStringTypeUsage(
                        MetadataWorkspace.GetModelPrimitiveType(PrimitiveTypeKind.String), true, false);
                    columns.Add(discriminatorColumn, type);
                }
            }
            var rowType = new RowType(columns.Select(c => new EdmProperty(c.Key, c.Value)));
            var result = TypeUsage.Create(new CollectionType(TypeUsage.Create(rowType)));
            return result;
        }
internal TypeUsage GetExpectedTargetResultType ( int resultSetIndex ) { var resultMapping = GetResultMapping ( resultSetIndex ) ; var columns = new Dictionary < string , TypeUsage > ( ) ; IEnumerable < StructuralType > structuralTypes ; if ( 0 == resultMapping . NormalizedEntityTypeMappings . Count ) { StructuralType structuralType ; MetadataHelper . TryGetFunctionImportReturnType ( FunctionImport , resultSetIndex , out structuralType ) ; Debug . Assert ( null != structuralType , " " ) ; structuralTypes = new [ ] { structuralType } ; } else { structuralTypes = resultMapping . MappedEntityTypes . Cast < StructuralType > ( ) ; } foreach ( var structuralType in structuralTypes ) { foreach ( EdmProperty property in TypeHelpers . GetAllStructuralMembers ( structuralType ) ) { columns [ property . Name ] = property . TypeUsage ; } } foreach ( var discriminatorColumn in GetDiscriminatorColumns ( resultSetIndex ) ) { if ( ! columns . ContainsKey ( discriminatorColumn ) ) { var type = TypeUsage . CreateStringTypeUsage ( MetadataWorkspace . GetModelPrimitiveType ( PrimitiveTypeKind . String ) , true , false ) ; columns . Add ( discriminatorColumn , type ) ; } } var rowType = new RowType ( columns . Select ( c => new EdmProperty ( c . Key , c . Value ) ) ) ; var result = TypeUsage . Create ( new CollectionType ( TypeUsage . Create ( rowType ) ) ) ; return result ; }
Determines the expected shape of store results.
Determines the expected shape of store results .
// Collect all columns as name-type pairs. // Figure out which entity types we expect to yield from the function. // No explicit type mappings; just use the type specified in the ReturnType attribute on the function. // Types are explicitly mapped. // Gather columns corresponding to all properties. // NOTE: if a complex type is encountered, the column map generator will // throw. For now, we just let them through. // We expect to see each property multiple times, so we use indexer rather than // .Add. // Gather discriminator columns. // CONSIDER: we assume that discriminatorColumns are all string types. In practice, // we're flexible about the runtime type during materialization, so the provider's // decision is hopefully irrelevant. The alternative is to require typed stored // procedure declarations in the SSDL, which is too much of a burden on the user and/or the // tools (there is no reliable way of determining this metadata automatically from SQL // Server). // Expected type is a collection of rows
None
resultSetIndex
int
remarks
Requires that the given function import mapping refers to a Collection(Entity) or Collection(ComplexType) CSDL
function.
Requires that the given function import mapping refers to a Collection ( Entity ) or Collection ( ComplexType ) CSDL function .