Example #1
0
        /// <summary>
        /// Adds the specified referential constraint.
        /// </summary>
        /// <param name="referentialConstraint">The referential constraint.</param>
        public void Add(ReferentialConstraint referentialConstraint)
        {
            if (this.ReferentialConstraint != null)
            {
                throw new TaupoInvalidOperationException("This association set already has a referential constraint.");
            }

            this.ReferentialConstraint = referentialConstraint;
        }
        /// <summary>
        /// Performs a deep copy of the specified <see cref="ReferentialConstraint"/>.
        /// </summary>
        /// <param name="referentialConstraint">The <see cref="ReferentialConstraint"/> to deep copy.</param>
        /// <returns>A deep copy of the <see cref="ReferentialConstraint"/>.</returns>
        private static ReferentialConstraint Clone(this ReferentialConstraint referentialConstraint)
        {
            if (referentialConstraint == null)
            {
                return(null);
            }

            var clone = new ReferentialConstraint()
                        .WithDependentProperties(
                referentialConstraint.DependentAssociationEnd.RoleName,
                referentialConstraint.DependentProperties.Select(m => new MemberPropertyReference(m.Name)).ToArray())
                        .ReferencesPrincipalProperties(
                referentialConstraint.PrincipalAssociationEnd.RoleName,
                referentialConstraint.PrincipalProperties.Select(m => new MemberPropertyReference(m.Name)).ToArray());

            CopyAnnotations(clone, referentialConstraint.Annotations);

            return(clone);
        }
Example #3
0
        private ReferentialConstraint ParseReferentialConstraint(XElement constraintElement)
        {
            var constraint = new ReferentialConstraint();
            var principalElement = constraintElement.Elements().Single(el => this.IsXsdlElement(el, "Principal"));
            var dependentElement = constraintElement.Elements().Single(el => this.IsXsdlElement(el, "Dependent"));

            constraint.PrincipalAssociationEnd = new AssociationEndReference(principalElement.GetRequiredAttributeValue("Role"));
            constraint.DependentAssociationEnd = new AssociationEndReference(dependentElement.GetRequiredAttributeValue("Role"));

            this.ParseConstraintProperties(constraint.PrincipalProperties, principalElement);
            this.ParseConstraintProperties(constraint.DependentProperties, dependentElement);

            this.ParseAnnotations(constraint, constraintElement);
            return constraint;
        }
        private void CompareReferentialConstraint(ReferentialConstraint expectedReferentialConstraint, ReferentialConstraint actualReferentialConstraint)
        {
            this.SatisfiesEquals(
                expectedReferentialConstraint.PrincipalAssociationEnd.RoleName,
                actualReferentialConstraint.PrincipalAssociationEnd.RoleName,
                "Principal end does not match.");

            this.SatisfiesEquals(
                expectedReferentialConstraint.DependentAssociationEnd.RoleName,
                actualReferentialConstraint.DependentAssociationEnd.RoleName,
                "Dependent end does not match.");

            bool principalCountMatches = this.SatisfiesEquals(
                    expectedReferentialConstraint.PrincipalProperties.Count,
                    actualReferentialConstraint.PrincipalProperties.Count,
                    "Princpal end property count does not match.");

            bool dependentCountMatches = this.SatisfiesEquals(
                    expectedReferentialConstraint.DependentProperties.Count,
                    actualReferentialConstraint.DependentProperties.Count,
                    "Dependent end property count does not match.");

            if (principalCountMatches && dependentCountMatches)
            {
                // Ordering doesn't need to be exact match
                // As long as principal properties and dependent properties are consistent, it's fine.
                for (int originalIndex = 0; originalIndex < expectedReferentialConstraint.PrincipalProperties.Count; originalIndex++)
                {
                    string propertyName = expectedReferentialConstraint.PrincipalProperties[originalIndex].Name;
                    MemberProperty actualProperty = actualReferentialConstraint.PrincipalProperties.SingleOrDefault(p => p.Name == propertyName);
                    int actualIndex = actualReferentialConstraint.PrincipalProperties.IndexOf(actualProperty);

                    if (this.SatisfiesCondition(actualIndex >= 0, "Cannot find property '{0}' in ReferentialConstraint PrincipalEnd.", propertyName))
                    {
                        this.SatisfiesEquals(
                            expectedReferentialConstraint.DependentProperties[originalIndex].Name,
                            actualReferentialConstraint.DependentProperties[actualIndex].Name,
                            "Dependent end property #{0} does not match.",
                            originalIndex);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Adds the specified referential constraint.
        /// </summary>
        /// <param name="referentialConstraint">The referential constraint.</param>
        public void Add(ReferentialConstraint referentialConstraint)
        {
            if (this.ReferentialConstraint != null)
            {
                throw new TaupoInvalidOperationException("This association set already has a referential constraint.");
            }

            this.ReferentialConstraint = referentialConstraint;
        }
 /// <summary>
 /// Visits referential constraint
 /// </summary>
 /// <param name="referentialConstraint">referential constraint to visit</param>
 protected virtual void VisitReferentialConstraint(ReferentialConstraint referentialConstraint)
 {
     this.VisitAnnotatedItem(referentialConstraint);
 }
 private XElement GenerateReferentialConstrait(ReferentialConstraint rc, XNamespace xmlNamespace)
 {
     return new XElement(
         xmlNamespace + "ReferentialConstraint",
         this.GenerateDocumentation(xmlNamespace, rc),
         this.GenerateReferentialEnd("Principal", rc.PrincipalAssociationEnd, rc.PrincipalProperties, xmlNamespace),
         this.GenerateReferentialEnd("Dependent", rc.DependentAssociationEnd, rc.DependentProperties, xmlNamespace),
         this.GenerateAnnotations(xmlNamespace, rc));
 }