src/Shared/EntityFramework/Core/Mapping/FunctionImportMappingNonComposable.cs
// <summary>
// Given discriminator values (ordinally aligned with DiscriminatorColumns), determines
// the entity type to return. Throws a CommandExecutionException if the type is ambiguous.
// </summary>
Given discriminator values (ordinally aligned with DiscriminatorColumns), determines
the entity type to return. Throws a CommandExecutionException if the type is ambiguous.
Given discriminator values ( ordinally aligned with DiscriminatorColumns ) determines the entity type to return . Throws a CommandExecutionException if the type is ambiguous .
internal EntityType Discriminate(object[] discriminatorValues, int resultSetIndex)
        {
            var resultMapping = GetResultMapping(resultSetIndex);
            Debug.Assert(resultMapping != null);
            var typeCandidates = new BitArray(resultMapping.MappedEntityTypes.Count, true);
            foreach (var typeMapping in resultMapping.NormalizedEntityTypeMappings)
            {
                var matches = true;
                var columnConditions = typeMapping.ColumnConditions;
                for (var i = 0; i < columnConditions.Count; i++)
                {
                    if (null != columnConditions[i]
                        && 
                        !columnConditions[i].ColumnValueMatchesCondition(discriminatorValues[i]))
                    {
                        matches = false;
                        break;
                    }
                }
                if (matches)
                {
                    typeCandidates = typeCandidates.And(typeMapping.ImpliedEntityTypes);
                }
                else
                {
                    typeCandidates = typeCandidates.And(typeMapping.ComplementImpliedEntityTypes);
                }
            }
            EntityType entityType = null;
            for (var i = 0; i < typeCandidates.Length; i++)
            {
                if (typeCandidates[i])
                {
                    if (null != entityType)
                    {
                        throw new EntityCommandExecutionException(Strings.ADP_InvalidDataReaderUnableToDetermineType);
                    }
                    entityType = resultMapping.MappedEntityTypes[i];
                }
            }
            if (null == entityType)
            {
                throw new EntityCommandExecutionException(Strings.ADP_InvalidDataReaderUnableToDetermineType);
            }
            return entityType;
        }
internal EntityType Discriminate ( object [ ] discriminatorValues , int resultSetIndex ) { var resultMapping = GetResultMapping ( resultSetIndex ) ; Debug . Assert ( resultMapping != null ) ; var typeCandidates = new BitArray ( resultMapping . MappedEntityTypes . Count , true ) ; foreach ( var typeMapping in resultMapping . NormalizedEntityTypeMappings ) { var matches = true ; var columnConditions = typeMapping . ColumnConditions ; for ( var i = 0 ; i < columnConditions . Count ; i ++ ) { if ( null != columnConditions [ i ] && ! columnConditions [ i ] . ColumnValueMatchesCondition ( discriminatorValues [ i ] ) ) { matches = false ; break ; } } if ( matches ) { typeCandidates = typeCandidates . And ( typeMapping . ImpliedEntityTypes ) ; } else { typeCandidates = typeCandidates . And ( typeMapping . ComplementImpliedEntityTypes ) ; } } EntityType entityType = null ; for ( var i = 0 ; i < typeCandidates . Length ; i ++ ) { if ( typeCandidates [ i ] ) { if ( null != entityType ) { throw new EntityCommandExecutionException ( Strings . ADP_InvalidDataReaderUnableToDetermineType ) ; } entityType = resultMapping . MappedEntityTypes [ i ] ; } } if ( null == entityType ) { throw new EntityCommandExecutionException ( Strings . ADP_InvalidDataReaderUnableToDetermineType ) ; } return entityType ; }
Given discriminator values (ordinally aligned with DiscriminatorColumns), determines
the entity type to return.
Given discriminator values ( ordinally aligned with DiscriminatorColumns ) determines the entity type to return .
// initialize matching types bit map // check if this type mapping is matched // this discriminator doesn't matter for the given condition // if the type condition is met, narrow the set of type candidates // if the type condition fails, all implied types are eliminated // (the type mapping fragment is a co-implication, so a type is no longer // a candidate if any condition referring to it is false) // find matching type condition // if there is no match, raise an exception
discriminatorValues
object[]
resultSetIndex
int