// effects: Given a store-side container, returns all the foreign key
        // constraints specified for different tables
        internal static List <ForeignConstraint> GetForeignConstraints(EntityContainer container)
        {
            List <ForeignConstraint> foreignKeyConstraints = new List <ForeignConstraint>();

            // Go through all the extents and get the associations
            foreach (EntitySetBase extent in container.BaseEntitySets)
            {
                AssociationSet relationSet = extent as AssociationSet;

                if (relationSet == null)
                {
                    continue;
                }
                // Keep track of the end to EntitySet mapping
                Dictionary <string, EntitySet> endToExtents = new Dictionary <string, EntitySet>();

                foreach (AssociationSetEnd end in relationSet.AssociationSetEnds)
                {
                    endToExtents.Add(end.Name, end.EntitySet);
                }

                AssociationType relationType = relationSet.ElementType;
                // Go through each referential constraint, determine the name
                // of the tables that the constraint refers to and then
                // create the foreign key constraint between the tables
                // Wow! We go to great lengths to make it cumbersome for a
                // programmer to deal with foreign keys
                foreach (ReferentialConstraint constraint in relationType.ReferentialConstraints)
                {
                    // Note: We are correlating the constraint's roles with
                    // the ends above using the role names, i.e.,
                    // FromRole.Name and ToRole.Name here and end.Role above
                    EntitySet         parentExtent         = endToExtents[constraint.FromRole.Name];
                    EntitySet         childExtent          = endToExtents[constraint.ToRole.Name];
                    ForeignConstraint foreignKeyConstraint = new ForeignConstraint(relationSet, parentExtent, childExtent,
                                                                                   constraint.FromProperties, constraint.ToProperties);
                    foreignKeyConstraints.Add(foreignKeyConstraint);
                }
            }
            return(foreignKeyConstraints);
        }
        // effects: Given a store-side container, returns all the foreign key
        // constraints specified for different tables
        internal static List<ForeignConstraint> GetForeignConstraints(EntityContainer container)
        {
            var foreignKeyConstraints = new List<ForeignConstraint>();

            // Go through all the extents and get the associations
            foreach (var extent in container.BaseEntitySets)
            {
                var relationSet = extent as AssociationSet;

                if (relationSet == null)
                {
                    continue;
                }
                // Keep track of the end to EntitySet mapping
                var endToExtents = new Dictionary<string, EntitySet>();

                foreach (var end in relationSet.AssociationSetEnds)
                {
                    endToExtents.Add(end.Name, end.EntitySet);
                }

                var relationType = relationSet.ElementType;
                // Go through each referential constraint, determine the name
                // of the tables that the constraint refers to and then
                // create the foreign key constraint between the tables
                // Wow! We go to great lengths to make it cumbersome for a
                // programmer to deal with foreign keys
                foreach (var constraint in relationType.ReferentialConstraints)
                {
                    // Note: We are correlating the constraint's roles with
                    // the ends above using the role names, i.e.,
                    // FromRole.Name and ToRole.Name here and end.Role above
                    var parentExtent = endToExtents[constraint.FromRole.Name];
                    var childExtent = endToExtents[constraint.ToRole.Name];
                    var foreignKeyConstraint = new ForeignConstraint(
                        relationSet, parentExtent, childExtent,
                        constraint.FromProperties, constraint.ToProperties);
                    foreignKeyConstraints.Add(foreignKeyConstraint);
                }
            }
            return foreignKeyConstraints;
        }