コード例 #1
0
        /// <summary>
        ///     Retrieves an enumerable collection of all ReferentialConstraints in this SSDL/StoreItemCollection
        /// </summary>
        /// <param name="storeItemCollection">StoreItemCollection representing the SSDL</param>
        /// <returns>The list of ReferentialConstraints.</returns>
        public static IEnumerable <ReferentialConstraint> GetAllReferentialConstraints(this StoreItemCollection storeItemCollection)
        {
            var refConstraints = new List <ReferentialConstraint>();

            foreach (AssociationType association in storeItemCollection.GetAllAssociations())
            {
                refConstraints.AddRange(association.ReferentialConstraints);
            }
            return(refConstraints);
        }
コード例 #2
0
        // 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>
        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);
        }