private void PopulateKeyConstraintsForRelationshipSet(
            SchemaConstraints <BasicKeyConstraint> constraints)
        {
            AssociationSet   extent = this.m_cellQuery.Extent as AssociationSet;
            Set <MemberPath> set    = new Set <MemberPath>(MemberPath.EqualityComparer);
            bool             flag   = false;

            foreach (AssociationSetEnd associationSetEnd in extent.AssociationSetEnds)
            {
                AssociationEndMember associationEndMember = associationSetEnd.CorrespondingAssociationEndMember;
                List <ExtentKey>     keysForEntityType    = ExtentKey.GetKeysForEntityType(new MemberPath((EntitySetBase)extent, (EdmMember)associationEndMember), associationSetEnd.EntitySet.ElementType);
                if (MetadataHelper.DoesEndFormKey(extent, associationEndMember))
                {
                    this.AddKeyConstraints((IEnumerable <ExtentKey>)keysForEntityType, constraints);
                    flag = true;
                }
                set.AddRange(keysForEntityType[0].KeyFields);
            }
            if (flag)
            {
                return;
            }
            this.AddKeyConstraints((IEnumerable <ExtentKey>) new ExtentKey[1]
            {
                new ExtentKey((IEnumerable <MemberPath>)set)
            }, constraints);
        }
Example #2
0
        // requires: this to correspond to a cell relation for an entityset (m_cellQuery.Extent)
        // effects: Adds any key constraints present in this to constraints
        private void PopulateKeyConstraintsForEntitySet(BasicSchemaConstraints constraints)
        {
            var prefix     = new MemberPath(m_cellQuery.Extent);
            var entityType = (EntityType)m_cellQuery.Extent.ElementType;

            // Get all the keys for the entity type and create the key constraints
            var keys = ExtentKey.GetKeysForEntityType(prefix, entityType);

            AddKeyConstraints(keys, constraints);
        }
Example #3
0
        // requires: this to correspond to a cell relation for an association set (m_cellQuery.Extent)
        // effects: Adds any key constraints present in this relation in
        // constraints
        private void PopulateKeyConstraintsForRelationshipSet(BasicSchemaConstraints constraints)
        {
            var relationshipSet = m_cellQuery.Extent as AssociationSet;
            // Gather all members of all keys
            // CHANGE_ADYA_FEATURE_KEYS: assume that an Entity has exactly one key. Otherwise we
            // have to take a cross-product of all keys

            // Keep track of all the key members for the association in a set
            // so that if no end corresponds to a key, we use all the members
            // to form the key
            var associationKeyMembers = new Set <MemberPath>(MemberPath.EqualityComparer);
            var hasAnEndThatFormsKey  = false;

            // Determine the keys of each end. If the end forms a key, add it
            // as a key to the set

            foreach (var end in relationshipSet.AssociationSetEnds)
            {
                var endMember = end.CorrespondingAssociationEndMember;

                var prefix = new MemberPath(relationshipSet, endMember);
                var keys   = ExtentKey.GetKeysForEntityType(prefix, end.EntitySet.ElementType);
                Debug.Assert(keys.Count > 0, "No keys for entity?");
                Debug.Assert(keys.Count == 1, "Currently, we only support primary keys");

                if (MetadataHelper.DoesEndFormKey(relationshipSet, endMember))
                {
                    // This end has is a key end
                    AddKeyConstraints(keys, constraints);
                    hasAnEndThatFormsKey = true;
                }
                // Add the members of the (only) key to associationKey
                associationKeyMembers.AddRange(keys[0].KeyFields);
            }
            // If an end forms a key then that key implies the full key
            if (false == hasAnEndThatFormsKey)
            {
                // No end is a key -- take all the end members and make a key
                // based on that
                var key  = new ExtentKey(associationKeyMembers);
                var keys = new[] { key };
                AddKeyConstraints(keys, constraints);
            }
        }
 private void PopulateKeyConstraintsForEntitySet(
     SchemaConstraints <BasicKeyConstraint> constraints)
 {
     this.AddKeyConstraints((IEnumerable <ExtentKey>)ExtentKey.GetKeysForEntityType(new MemberPath(this.m_cellQuery.Extent), (EntityType)this.m_cellQuery.Extent.ElementType), constraints);
 }