src/Misc/EFTools/EntityDesignDatabaseGeneration/MetadataWorkspaceExtensions.cs
// TODO: in order to properly identify this we may need to add custom annotations in the SSDL 
/// <summary>
///     We can infer that something is a join table in the SSDL if:
///     1. There are two associations originating from it
///     2. The two ends on the table are *
///     3. The other ends on the associations are 1
///     4. The number of properties in the table is equal to the sum of all the key properties on the other ends of both associations
///     5. All properties in the table are key properties
/// </summary>
/// <param name="entityType">The EntityType to test.</param>
/// <param name="store">The StoreItemCollection containing EntityType.</param>
/// <returns>true if the specified EntityType is a join table; otherwise, false.</returns>
We can infer that something is a join table in the SSDL if:
1. There are two associations originating from it
2. The two ends on the table are
3. The other ends on the associations are 1
4. The number of properties in the table is equal to the sum of all the key properties on the other ends of both associations
5. All properties in the table are key properties
We can infer that something is a join table in the SSDL if : 1 . There are two associations originating from it 2 . The two ends on the table are 3 . The other ends on the associations are 1 4 . The number of properties in the table is equal to the sum of all the key properties on the other ends of both associations 5 . All properties in the table are key properties
public static bool IsJoinTable(this EntityType entityType, StoreItemCollection store)
        {
            var associations = store.GetAllAssociations().Where(a => a.IsAssociatedWithEntityType(entityType));
            if (associations.Count() == 2)
            {
                var sumOfAllKeyProperties = 0;
                var numEndsWithOneMultiplicity = 0;
                foreach (AssociationType association in associations)
                {
                    AssociationEndMember end1 = association.GetEnd1();
                    AssociationEndMember end2 = association.GetEnd2();
                    if ((end1.GetEntityType() == entityType)
                        && (end1.RelationshipMultiplicity == RelationshipMultiplicity.Many)
                        && (end2.RelationshipMultiplicity == RelationshipMultiplicity.One))
                    {
                        sumOfAllKeyProperties += end2.GetEntityType().GetKeyProperties().Count();
                        numEndsWithOneMultiplicity++;
                    }
                    else if ((end2.GetEntityType() == entityType)
                             && (end2.RelationshipMultiplicity == RelationshipMultiplicity.Many)
                             && (end1.RelationshipMultiplicity == RelationshipMultiplicity.One))
                    {
                        sumOfAllKeyProperties += end1.GetEntityType().GetKeyProperties().Count();
                        numEndsWithOneMultiplicity++;
                    }
                }
                int intersectCount = entityType.GetKeyProperties().Intersect(entityType.Properties).Count();
                if (numEndsWithOneMultiplicity == 2
                    && entityType.GetKeyProperties().Count() == sumOfAllKeyProperties
                    && entityType.GetKeyProperties().Count() == intersectCount
                    && entityType.Properties.Count == intersectCount)
                {
                    return true;
                }
            }
            return false;
        }
public static bool IsJoinTable ( this EntityType entityType , StoreItemCollection store ) { var associations = store . GetAllAssociations ( ) . Where ( a => a . IsAssociatedWithEntityType ( entityType ) ) ; if ( associations . Count ( ) == 2 ) { var sumOfAllKeyProperties = 0 ; var numEndsWithOneMultiplicity = 0 ; foreach ( AssociationType association in associations ) { AssociationEndMember end1 = association . GetEnd1 ( ) ; AssociationEndMember end2 = association . GetEnd2 ( ) ; if ( ( end1 . GetEntityType ( ) == entityType ) && ( end1 . RelationshipMultiplicity == RelationshipMultiplicity . Many ) && ( end2 . RelationshipMultiplicity == RelationshipMultiplicity . One ) ) { sumOfAllKeyProperties += end2 . GetEntityType ( ) . GetKeyProperties ( ) . Count ( ) ; numEndsWithOneMultiplicity ++ ; } else if ( ( end2 . GetEntityType ( ) == entityType ) && ( end2 . RelationshipMultiplicity == RelationshipMultiplicity . Many ) && ( end1 . RelationshipMultiplicity == RelationshipMultiplicity . One ) ) { sumOfAllKeyProperties += end1 . GetEntityType ( ) . GetKeyProperties ( ) . Count ( ) ; numEndsWithOneMultiplicity ++ ; } } int intersectCount = entityType . GetKeyProperties ( ) . Intersect ( entityType . Properties ) . Count ( ) ; if ( numEndsWithOneMultiplicity == 2 && entityType . GetKeyProperties ( ) . Count ( ) == sumOfAllKeyProperties && entityType . GetKeyProperties ( ) . Count ( ) == intersectCount && entityType . Properties . Count == intersectCount ) { return true ; } } return false ; }
We can infer that something is a join table in the SSDL if:
1.
We can infer that something is a join table in the SSDL if : 1 .
true if the specified EntityType is a join table; otherwise, false.
true if the specified EntityType is a join table ; otherwise false .
EntityType
this
store
StoreItemCollection
The StoreItemCollection containing EntityType.
The StoreItemCollection containing EntityType .
entityType
The EntityType to test.
The EntityType to test .