src/Shared/EntityFramework/ModelConfiguration/Edm/AssociationTypeExtensions.cs
// <summary>
// Attempt to determine the principal and dependent ends of this association.
// The following table illustrates the solution space.
// Source | Target || Prin  | Dep   |
// -------|--------||-------|-------|
// 1      | 1      || -     | -     |
// 1      | 0..1   || Sr    | Ta    |
// 1      | *      || Sr    | Ta    |
// 0..1   | 1      || Ta    | Sr    |
// 0..1   | 0..1   || -     | -     |
// 0..1   | *      || Sr    | Ta    |
// *      | 1      || Ta    | Sr    |
// *      | 0..1   || Ta    | Sr    |
// *      | *      || -     | -     |
// </summary>
Attempt to determine the principal and dependent ends of this association.
The following table illustrates the solution space.
Attempt to determine the principal and dependent ends of this association . The following table illustrates the solution space .
public static bool TryGuessPrincipalAndDependentEnds(
            this AssociationType associationType,
            out AssociationEndMember principalEnd,
            out AssociationEndMember dependentEnd)
        {
            DebugCheck.NotNull(associationType);
            Debug.Assert(associationType.SourceEnd != null);
            Debug.Assert(associationType.TargetEnd != null);
            principalEnd = dependentEnd = null;
            var sourceEnd = associationType.SourceEnd;
            var targetEnd = associationType.TargetEnd;
            if (sourceEnd.RelationshipMultiplicity
                != targetEnd.RelationshipMultiplicity)
            {
                principalEnd
                    = (sourceEnd.IsRequired()
                       || (sourceEnd.IsOptional() && targetEnd.IsMany()))
                          ? sourceEnd
                          : targetEnd;
                dependentEnd
                    = (principalEnd == sourceEnd)
                          ? targetEnd
                          : sourceEnd;
            }
            return (principalEnd != null);
        }
public static bool TryGuessPrincipalAndDependentEnds ( this AssociationType associationType , out AssociationEndMember principalEnd , out AssociationEndMember dependentEnd ) { DebugCheck . NotNull ( associationType ) ; Debug . Assert ( associationType . SourceEnd != null ) ; Debug . Assert ( associationType . TargetEnd != null ) ; principalEnd = dependentEnd = null ; var sourceEnd = associationType . SourceEnd ; var targetEnd = associationType . TargetEnd ; if ( sourceEnd . RelationshipMultiplicity != targetEnd . RelationshipMultiplicity ) { principalEnd = ( sourceEnd . IsRequired ( ) || ( sourceEnd . IsOptional ( ) && targetEnd . IsMany ( ) ) ) ? sourceEnd : targetEnd ; dependentEnd = ( principalEnd == sourceEnd ) ? targetEnd : sourceEnd ; } return ( principalEnd != null ) ; }
Attempt to determine the principal and dependent ends of this association.
Attempt to determine the principal and dependent ends of this association .
AssociationType
this
AssociationEndMember
out