/// <summary>
 /// Initializes a new instance of the NavigationProperty class.
 /// </summary>
 /// <param name="navigationPropertyName">Name of the navigation property.</param>
 /// <param name="association">The association.</param>
 /// <param name="fromAssociationEnd">From association end.</param>
 /// <param name="toAssociationEnd">To association end.</param>
 public NavigationProperty(string navigationPropertyName, AssociationType association, AssociationEnd fromAssociationEnd, AssociationEnd toAssociationEnd)
 {
     this.Name = navigationPropertyName;
     this.Association = association;
     this.FromAssociationEnd = fromAssociationEnd;
     this.ToAssociationEnd = toAssociationEnd;
 }
 /// <summary>
 /// Get navigate result for specified associaion type and end
 /// </summary>
 /// <param name="associationType">The association type.</param>
 /// <param name="toEnd">The end to navigate to.</param>
 /// <returns>The result query entity value(s) for navigate.</returns>
 public QueryValue GetNavigateResult(AssociationType associationType, AssociationEnd toEnd)
 {
     ExceptionUtilities.Assert(this.navigateResultLookup.ContainsKey(associationType), "Invalid AssociationType for Navigate: {0}", associationType.FullName);
     var lookupBasedOnEnd = this.navigateResultLookup[associationType];
     
     ExceptionUtilities.Assert(lookupBasedOnEnd.ContainsKey(toEnd), "Invalid ToEnd for Navigate: {0}.{1}, from {2}.", associationType.FullName, toEnd.RoleName, (this.Type as QueryEntityType).EntityType.FullName);
     return lookupBasedOnEnd[toEnd];
 }
        internal void SetNavigateResult(AssociationType associationType, AssociationEnd toEnd, QueryValue result)
        {
            if (!this.navigateResultLookup.ContainsKey(associationType))
            {
                this.navigateResultLookup.Add(associationType, new Dictionary<AssociationEnd, QueryValue>());
            }

            Dictionary<AssociationEnd, QueryValue> lookupBasedOnEnd = this.navigateResultLookup[associationType];
            lookupBasedOnEnd[toEnd] = result;
        }
        /// <summary>
        /// Helper to easily establish Principal (by properties)
        /// </summary>
        /// <param name="principalEnd">The principal end.</param>
        /// <param name="properties">the (pk) properties on Principal</param>
        /// <returns>this RerentialConstraint</returns>
        public ReferentialConstraint ReferencesPrincipalProperties(AssociationEnd principalEnd, params MemberProperty[] properties)
        {
            this.PrincipalAssociationEnd = principalEnd;
            
            foreach (MemberProperty p in properties)
            {
                this.PrincipalProperties.Add(p);
            }

            return this;
        }
Beispiel #5
0
        /// <summary>
        /// Helper to easily establish Principal (by properties)
        /// </summary>
        /// <param name="principalEnd">The principal end.</param>
        /// <param name="properties">the (pk) properties on Principal</param>
        /// <returns>this RerentialConstraint</returns>
        public ReferentialConstraint ReferencesPrincipalProperties(AssociationEnd principalEnd, params MemberProperty[] properties)
        {
            this.PrincipalAssociationEnd = principalEnd;

            foreach (MemberProperty p in properties)
            {
                this.PrincipalProperties.Add(p);
            }

            return(this);
        }
        /// <summary>
        /// Helper to easily establish Dependent (by properties)
        /// </summary>
        /// <param name="dependentEnd">the dependent end of the association</param>
        /// <param name="properties">the (fk) properties on Dependent</param>
        /// <returns>this RerentialConstraint</returns>
        public ReferentialConstraint WithDependentProperties(AssociationEnd dependentEnd, params MemberProperty[] properties)
        {
            this.DependentAssociationEnd = dependentEnd;
            
            foreach (MemberProperty p in properties)
            {
                this.DependentProperties.Add(p);
            }

            return this;
        }
Beispiel #7
0
        /// <summary>
        /// Helper to easily establish Dependent (by properties)
        /// </summary>
        /// <param name="dependentEnd">the dependent end of the association</param>
        /// <param name="properties">the (fk) properties on Dependent</param>
        /// <returns>this RerentialConstraint</returns>
        public ReferentialConstraint WithDependentProperties(AssociationEnd dependentEnd, params MemberProperty[] properties)
        {
            this.DependentAssociationEnd = dependentEnd;

            foreach (MemberProperty p in properties)
            {
                this.DependentProperties.Add(p);
            }

            return(this);
        }
        /// <summary>
        /// Performs a deep copy of the specified <see cref="AssociationEnd"/>.
        /// </summary>
        /// <param name="associationEnd">The <see cref="AssociationEnd"/> to deep copy.</param>
        /// <returns>A deep copy of the <see cref="AssociationEnd"/>.</returns>
        private static AssociationEnd Clone(this AssociationEnd associationEnd)
        {
            var clone = new AssociationEnd()
            {
                DeleteBehavior = associationEnd.DeleteBehavior,
                Multiplicity   = associationEnd.Multiplicity,
                RoleName       = associationEnd.RoleName,
                EntityType     = associationEnd.EntityType.Name
            };

            CopyAnnotations(clone, associationEnd.Annotations);

            return(clone);
        }
Beispiel #9
0
 /// <summary>
 /// Add an AssociationEnd to the <see cref="Ends"/> collection.
 /// </summary>
 /// <param name="end">the AssociationEnd to be added</param>
 public void Add(AssociationEnd end)
 {
     this.Ends.Add(end);
 }
Beispiel #10
0
        private AssociationEnd ParseAssociationEnd(XElement associationEndElement)
        {
            var roleName = associationEndElement.GetRequiredAttributeValue("Role");

            string entityTypeNamespace = this.ParseEdmTypeName(associationEndElement.GetRequiredAttributeValue("Type"))[0];
            string entityTypeName = this.ParseEdmTypeName(associationEndElement.GetRequiredAttributeValue("Type"))[1];

            EndMultiplicity multiplicity = this.ParseEndMultiplicity(associationEndElement.GetRequiredAttributeValue("Multiplicity"));
            OperationAction onDeleteAction = associationEndElement.Descendants().Any(e => e.Name.LocalName.Equals("OnDelete") && e.Attribute("Action").Value.Equals("Cascade")) ? OperationAction.Cascade : OperationAction.None;
            AssociationEnd end = new AssociationEnd(roleName, new EntityTypeReference(entityTypeNamespace, entityTypeName), multiplicity, onDeleteAction);
            this.ParseAnnotations(end, associationEndElement);
            return end;
        }
 private XElement GenerateAssociationEnd(XNamespace xmlNamespace, AssociationEnd end)
 {
     return new XElement(
         xmlNamespace + "End",
         new XAttribute("Role", end.RoleName),
         new XAttribute("Type", this.GetFullyQualifiedName(end.EntityType)),
         new XAttribute("Multiplicity", this.GetMultiplicityString(end.Multiplicity)),
         this.GenerateDocumentation(xmlNamespace, end),
         this.GenerateOnDelete(end, xmlNamespace),
         this.GenerateAnnotations(xmlNamespace, end));
 }
Beispiel #12
0
 /// <summary>
 /// Gets the other end of the association type.
 /// </summary>
 /// <param name="end">The end for which to get other end.</param>
 /// <returns>The other end of the association type.</returns>
 public AssociationEnd GetOtherEnd(AssociationEnd end)
 {
     return(this.Ends.Where(e => e != end).Single());
 }
 private XElement GenerateOnDelete(AssociationEnd end, XNamespace xmlNamespace)
 {
     if (end.DeleteBehavior == OperationAction.Cascade)
     {
         return new XElement(
             xmlNamespace + "OnDelete",
             new XAttribute("Action", "Cascade"));
     }
     else
     {
         return null;
     }
 }
 private XElement GenerateReferentialEnd(string endTypeName, AssociationEnd end, IEnumerable<MemberProperty> properties, XNamespace xmlNamespace)
 {
     var propRefs = from p in properties
                    select new XElement(
                             xmlNamespace + "PropertyRef",
                             new XAttribute("Name", p.Name));
     return new XElement(
             xmlNamespace + endTypeName,
             new XAttribute("Role", end.RoleName),
             propRefs);
 }
 private void CompareAssociationEnd(AssociationEnd expectedEnd, AssociationEnd actualEnd)
 {
     this.SatisfiesEquals(expectedEnd.RoleName, actualEnd.RoleName, "RoleName not as expeted.");
     this.SatisfiesEquals(expectedEnd.Multiplicity, actualEnd.Multiplicity, "Multiplicity does not match on AssociationEnd '{0}'.", expectedEnd.RoleName);
     this.SatisfiesEquals(expectedEnd.EntityType.FullName, actualEnd.EntityType.FullName, "EntityType name does not match on AssociationEnd '{0}'.", expectedEnd.RoleName);
     this.SatisfiesEquals(expectedEnd.DeleteBehavior, actualEnd.DeleteBehavior, "DeleteBehavior does not match on AssociationEnd '{0}'.", expectedEnd.RoleName);
 }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the AssociationSetEnd class.
 /// </summary>
 /// <param name="associationEnd">The association end.</param>
 /// <param name="entitySet">The entity set.</param>
 public AssociationSetEnd(AssociationEnd associationEnd, EntitySet entitySet)
 {
     this.EntitySet      = entitySet;
     this.AssociationEnd = associationEnd;
 }
Beispiel #17
0
 /// <summary>
 /// Add an AssociationEnd to the <see cref="Ends"/> collection.
 /// </summary>
 /// <param name="end">the AssociationEnd to be added</param>
 public void Add(AssociationEnd end)
 {
     this.Ends.Add(end);
 }
Beispiel #18
0
 /// <summary>
 /// Initializes a new instance of the NavigationProperty class.
 /// </summary>
 /// <param name="navigationPropertyName">Name of the navigation property.</param>
 /// <param name="association">The association.</param>
 /// <param name="fromAssociationEnd">From association end.</param>
 /// <param name="toAssociationEnd">To association end.</param>
 public NavigationProperty(string navigationPropertyName, AssociationType association, AssociationEnd fromAssociationEnd, AssociationEnd toAssociationEnd)
 {
     this.Name               = navigationPropertyName;
     this.Association        = association;
     this.FromAssociationEnd = fromAssociationEnd;
     this.ToAssociationEnd   = toAssociationEnd;
 }
        private void CompareAssociationEnd(AssociationEnd expectedEnd, AssociationEnd actualEnd)
        {
            this.WriteErrorIfFalse(expectedEnd.Multiplicity == actualEnd.Multiplicity, "Expected Multiplicity to be '{0}' actual '{1}' on AssociationEnd {2}", expectedEnd.Multiplicity, actualEnd.Multiplicity, expectedEnd.RoleName);

            string expectedEntityTypeName = null;
            if (expectedEnd.EntityType != null)
            {
                expectedEntityTypeName = expectedEnd.EntityType.Name;
            }

            string actualEntityTypeName = null;
            if (actualEnd.EntityType != null)
            {
                actualEntityTypeName = actualEnd.EntityType.Name;
            }

            this.WriteErrorIfFalse(expectedEntityTypeName == actualEntityTypeName, "Expected EntityType Name to be '{0}' actual '{1}' on associationEnd {2}", expectedEntityTypeName, actualEntityTypeName, actualEnd.RoleName);
        }
 /// <summary>
 /// Gets the navigation property that starts at this <see cref="AssociationEnd"/>
 /// and navigates to the other <see cref="AssociationEnd"/>.
 /// </summary>
 /// <param name="end">The end to find the navigation property for</param>
 /// <returns>The navigation property, Null if no navigation is defined</returns>
 public static NavigationProperty FromNavigationProperty(this AssociationEnd end)
 {
     ExceptionUtilities.CheckArgumentNotNull(end, "end");
     return(end.EntityType.NavigationProperties.Where(n => n.FromAssociationEnd == end).SingleOrDefault());
 }
 /// <summary>
 /// Visit association end
 /// </summary>
 /// <param name="associationEnd">association end to visit</param>
 protected virtual void VisitAssociationEnd(AssociationEnd associationEnd)
 {
     this.VisitAnnotatedItem(associationEnd);
 }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the AssociationSetEnd class.
 /// </summary>
 /// <param name="associationEnd">The association end.</param>
 /// <param name="entitySet">The entity set.</param>
 public AssociationSetEnd(AssociationEnd associationEnd, EntitySet entitySet)
 {
     this.EntitySet = entitySet;
     this.AssociationEnd = associationEnd;
 }
Beispiel #23
0
 /// <summary>
 /// Gets the other end of the association type.
 /// </summary>
 /// <param name="end">The end for which to get other end.</param>
 /// <returns>The other end of the association type.</returns>
 public AssociationEnd GetOtherEnd(AssociationEnd end)
 {
     return this.Ends.Where(e => e != end).Single();
 }