Exemplo n.º 1
0
        internal void CreateAssociationConstraints(
            EntitySetBase extent,
            MemberDomainMap domainMap,
            EdmItemCollection edmItemCollection)
        {
            AssociationSet associationSet = extent as AssociationSet;

            if (associationSet == null)
            {
                return;
            }
            BoolExpression literal1 = BoolExpression.CreateLiteral((BoolLiteral) new RoleBoolean((EntitySetBase)associationSet), domainMap);
            HashSet <Pair <EdmMember, EntityType> > associationkeys = new HashSet <Pair <EdmMember, EntityType> >();

            foreach (AssociationEndMember associationEndMember in associationSet.ElementType.AssociationEndMembers)
            {
                EntityType type = (EntityType)((RefType)associationEndMember.TypeUsage.EdmType).ElementType;
                type.KeyMembers.All <EdmMember>((Func <EdmMember, bool>)(member =>
                {
                    associationkeys.Add(new Pair <EdmMember, EntityType>(member, type));
                    return(true);
                }));
            }
            foreach (AssociationSetEnd associationSetEnd in associationSet.AssociationSetEnds)
            {
                HashSet <EdmType> edmTypeSet = new HashSet <EdmType>();
                edmTypeSet.UnionWith(MetadataHelper.GetTypeAndSubtypesOf(associationSetEnd.CorrespondingAssociationEndMember.TypeUsage.EdmType, (ItemCollection)edmItemCollection, false));
                BoolExpression isOfTypeCondition = FragmentQueryKB.CreateIsOfTypeCondition(new MemberPath((EntitySetBase)associationSetEnd.EntitySet), (IEnumerable <EdmType>)edmTypeSet, domainMap);
                BoolExpression literal2          = BoolExpression.CreateLiteral((BoolLiteral) new RoleBoolean(associationSetEnd), domainMap);
                BoolExpression and = BoolExpression.CreateAnd(BoolExpression.CreateLiteral((BoolLiteral) new RoleBoolean((EntitySetBase)associationSetEnd.EntitySet), domainMap), isOfTypeCondition);
                this.AddImplication(literal2.Tree, and.Tree);
                if (MetadataHelper.IsEveryOtherEndAtLeastOne(associationSet, associationSetEnd.CorrespondingAssociationEndMember))
                {
                    this.AddImplication(and.Tree, literal2.Tree);
                }
                if (MetadataHelper.DoesEndKeySubsumeAssociationSetKey(associationSet, associationSetEnd.CorrespondingAssociationEndMember, associationkeys))
                {
                    this.AddEquivalence(literal2.Tree, literal1.Tree);
                }
            }
            foreach (ReferentialConstraint referentialConstraint in associationSet.ElementType.ReferentialConstraints)
            {
                AssociationEndMember toRole         = (AssociationEndMember)referentialConstraint.ToRole;
                EntitySet            entitySetAtEnd = MetadataHelper.GetEntitySetAtEnd(associationSet, toRole);
                if (Helpers.IsSetEqual <EdmMember>(Helpers.AsSuperTypeList <EdmProperty, EdmMember>((IEnumerable <EdmProperty>)referentialConstraint.ToProperties), (IEnumerable <EdmMember>)entitySetAtEnd.ElementType.KeyMembers, (IEqualityComparer <EdmMember>)EqualityComparer <EdmMember> .Default) && referentialConstraint.FromRole.RelationshipMultiplicity.Equals((object)RelationshipMultiplicity.One))
                {
                    this.AddEquivalence(BoolExpression.CreateLiteral((BoolLiteral) new RoleBoolean(associationSet.AssociationSetEnds[0]), domainMap).Tree, BoolExpression.CreateLiteral((BoolLiteral) new RoleBoolean(associationSet.AssociationSetEnds[1]), domainMap).Tree);
                }
            }
        }
Exemplo n.º 2
0
        private void CreateVariableConstraintsRecursion(
            EdmType edmType,
            MemberPath currentPath,
            MemberDomainMap domainMap,
            EdmItemCollection edmItemCollection)
        {
            HashSet <EdmType> edmTypeSet1 = new HashSet <EdmType>();

            edmTypeSet1.UnionWith(MetadataHelper.GetTypeAndSubtypesOf(edmType, (ItemCollection)edmItemCollection, true));
            foreach (EdmType type in edmTypeSet1)
            {
                HashSet <EdmType> edmTypeSet2 = new HashSet <EdmType>();
                edmTypeSet2.UnionWith(MetadataHelper.GetTypeAndSubtypesOf(type, (ItemCollection)edmItemCollection, false));
                if (edmTypeSet2.Count != 0)
                {
                    BoolExpression not = BoolExpression.CreateNot(FragmentQueryKB.CreateIsOfTypeCondition(currentPath, (IEnumerable <EdmType>)edmTypeSet2, domainMap));
                    if (not.IsSatisfiable())
                    {
                        foreach (EdmProperty declaredOnlyMember in ((StructuralType)type).GetDeclaredOnlyMembers <EdmProperty>())
                        {
                            MemberPath memberPath = new MemberPath(currentPath, (EdmMember)declaredOnlyMember);
                            bool       flag       = MetadataHelper.IsNonRefSimpleMember((EdmMember)declaredOnlyMember);
                            if (domainMap.IsConditionMember(memberPath) || domainMap.IsProjectedConditionMember(memberPath))
                            {
                                List <Constant> constantList   = new List <Constant>(domainMap.GetDomain(memberPath));
                                BoolExpression  boolExpression = !flag?BoolExpression.CreateLiteral((BoolLiteral) new TypeRestriction(new MemberProjectedSlot(memberPath), new Domain(Constant.Undefined, (IEnumerable <Constant>)constantList)), domainMap) : BoolExpression.CreateLiteral((BoolLiteral) new ScalarRestriction(new MemberProjectedSlot(memberPath), new Domain(Constant.Undefined, (IEnumerable <Constant>)constantList)), domainMap);

                                this.AddEquivalence(not.Tree, boolExpression.Tree);
                            }
                            if (!flag)
                            {
                                this.CreateVariableConstraintsRecursion(memberPath.EdmType, memberPath, domainMap, edmItemCollection);
                            }
                        }
                    }
                }
            }
        }