internal static bool DoesEndKeySubsumeAssociationSetKey( AssociationSet assocSet, AssociationEndMember thisEnd, HashSet <Pair <EdmMember, EntityType> > associationkeys) { AssociationType elementType1 = assocSet.ElementType; EntityType thisEndsEntityType = (EntityType)((RefType)thisEnd.TypeUsage.EdmType).ElementType; HashSet <Pair <EdmMember, EntityType> > pairSet = new HashSet <Pair <EdmMember, EntityType> >(thisEndsEntityType.KeyMembers.Select <EdmMember, Pair <EdmMember, EntityType> >((Func <EdmMember, Pair <EdmMember, EntityType> >)(edmMember => new Pair <EdmMember, EntityType>(edmMember, thisEndsEntityType)))); foreach (ReferentialConstraint referentialConstraint in elementType1.ReferentialConstraints) { IEnumerable <EdmMember> edmMembers; EntityType elementType2; if (thisEnd.Equals((object)referentialConstraint.ToRole)) { edmMembers = Helpers.AsSuperTypeList <EdmProperty, EdmMember>((IEnumerable <EdmProperty>)referentialConstraint.FromProperties); elementType2 = (EntityType)((RefType)referentialConstraint.FromRole.TypeUsage.EdmType).ElementType; } else if (thisEnd.Equals((object)referentialConstraint.FromRole)) { edmMembers = Helpers.AsSuperTypeList <EdmProperty, EdmMember>((IEnumerable <EdmProperty>)referentialConstraint.ToProperties); elementType2 = (EntityType)((RefType)referentialConstraint.ToRole.TypeUsage.EdmType).ElementType; } else { continue; } foreach (EdmMember first in edmMembers) { associationkeys.Remove(new Pair <EdmMember, EntityType>(first, elementType2)); } } return(associationkeys.IsSubsetOf((IEnumerable <Pair <EdmMember, EntityType> >)pairSet)); }
internal static bool DoesEndKeySubsumeAssociationSetKey( AssociationSet assocSet, AssociationEndMember thisEnd, HashSet <Pair <EdmMember, EntityType> > associationkeys) { var assocType = assocSet.ElementType; var thisEndsEntityType = (EntityType)((RefType)thisEnd.TypeUsage.EdmType).ElementType; var thisEndKeys = new HashSet <Pair <EdmMember, EntityType> >( thisEndsEntityType.KeyMembers.Select(edmMember => new Pair <EdmMember, EntityType>(edmMember, thisEndsEntityType))); foreach (var constraint in assocType.ReferentialConstraints) { IEnumerable <EdmMember> otherEndProperties; EntityType otherEndType; if (thisEnd.Equals(constraint.ToRole)) { otherEndProperties = Helpers.AsSuperTypeList <EdmProperty, EdmMember>(constraint.FromProperties); otherEndType = (EntityType)((RefType)(constraint.FromRole).TypeUsage.EdmType).ElementType; } else if (thisEnd.Equals(constraint.FromRole)) { otherEndProperties = Helpers.AsSuperTypeList <EdmProperty, EdmMember>(constraint.ToProperties); otherEndType = (EntityType)((RefType)(constraint.ToRole).TypeUsage.EdmType).ElementType; } else { //this end not part of the referential constraint continue; } //Essentially ref constraints is an equality condition, so remove redundant members from entity set key foreach (var member in otherEndProperties) { associationkeys.Remove(new Pair <EdmMember, EntityType>(member, otherEndType)); } } //Now that all redundant members have been removed, is thisEnd the key of the entity set? return(associationkeys.IsSubsetOf(thisEndKeys)); }
// effects: Returns true iff every end other than "endPropery" has a lower // multiplicity of at least one internal static bool IsEveryOtherEndAtLeastOne(AssociationSet associationSet, AssociationEndMember member) { foreach (AssociationSetEnd end in associationSet.AssociationSetEnds) { AssociationEndMember endMember = end.CorrespondingAssociationEndMember; if (endMember.Equals(member) == false && GetLowerBoundOfMultiplicity(endMember.RelationshipMultiplicity) == 0) { return(false); } } return(true); }
internal static bool IsEveryOtherEndAtLeastOne( AssociationSet associationSet, AssociationEndMember member) { foreach (AssociationSetEnd associationSetEnd in associationSet.AssociationSetEnds) { AssociationEndMember associationEndMember = associationSetEnd.CorrespondingAssociationEndMember; if (!associationEndMember.Equals((object)member) && MetadataHelper.GetLowerBoundOfMultiplicity(associationEndMember.RelationshipMultiplicity) == 0) { return(false); } } return(true); }