/// <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;
 }
Example #2
0
 /// <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];
 }
Example #3
0
        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;
        }
        private void RemoveAssociation(AssociationType association)
        {
            foreach (var end in association.Ends.ToList())
            {
                var property = end.FromNavigationProperty();
                if (property != null)
                {
                    end.EntityType.NavigationProperties.Remove(property);
                }
            }

            var model = association.Model;
            model.Remove(association);
            var defaultContainer = model.EntityContainers.First();
            var set = defaultContainer.AssociationSets.SingleOrDefault(s => s.AssociationType.Name == association.Name);
            if (set != null)
            {
                defaultContainer.Remove(set);
            }
        } 
 private void CompareAssociationType(AssociationType expectedAssociationType, AssociationType actualAssociationType)
 {
     this.WriteErrorIfFalse(expectedAssociationType.Name == actualAssociationType.Name, "Expected AssociationType.Name to be '{0}' actual '{1}'", expectedAssociationType.Name, actualAssociationType.Name);
     this.WriteErrorIfFalse(expectedAssociationType.NamespaceName == actualAssociationType.NamespaceName, "Expected AssociationType.NamespaceName to be '{0}' actual '{1}'", expectedAssociationType.NamespaceName, actualAssociationType.NamespaceName);
 }
Example #6
0
        private AssociationType ParseAssociation(XElement associationTypeElement)
        {
            string name = associationTypeElement.GetRequiredAttributeValue("Name");
            var association = new AssociationType(this.CurrentNamespace, name);

            foreach (var associationEndElement in associationTypeElement.Elements().Where(el => this.IsXsdlElement(el, "End")))
            {
                association.Ends.Add(this.ParseAssociationEnd(associationEndElement));
            }

            var constraintElement = associationTypeElement.Elements().Where(el => this.IsXsdlElement(el, "ReferentialConstraint")).SingleOrDefault();
            if (constraintElement != null)
            {
                association.ReferentialConstraint = this.ParseReferentialConstraint(constraintElement);
            }

            this.ParseAnnotations(association, associationTypeElement);
            return association;
        }
Example #7
0
 /// <summary>
 /// Removes an <see cref="AssociationType"/> from the model.
 /// </summary>
 /// <param name="associationType">Associatin type to be removed</param>
 public void Remove(AssociationType associationType)
 {
     ExceptionUtilities.CheckArgumentNotNull(associationType, "associationType");
     ExceptionUtilities.Assert(associationType.Model == this, "Association type was not added to this model");
     ExceptionUtilities.Assert(this.associationsList.Remove(associationType), "Association type was not added to this model");
     associationType.Model = null;
 }
Example #8
0
 /// <summary>
 /// Adds new <see cref="AssociationType"/> to the model.
 /// </summary>
 /// <param name="associationType">Associatin type to be added</param>
 public void Add(AssociationType associationType)
 {
     ExceptionUtilities.CheckArgumentNotNull(associationType, "associationType");
     ExceptionUtilities.Assert(associationType.Model == null, "Association type was already added to another model");
     associationType.Model = this;
     this.associationsList.Add(associationType);
 }
        private void CompareAssociationType(AssociationType expectedAssociationType, AssociationType actualAssociationType)
        {
            this.SatisfiesEquals(expectedAssociationType.FullName, actualAssociationType.FullName, "AssociationType name does not match.");

            foreach (var expectedAssociationEnd in expectedAssociationType.Ends)
            {
                var actualAssociationEnds = actualAssociationType.Ends.Where(e => e.RoleName == expectedAssociationEnd.RoleName);
                if (this.SatisfiesEquals(1, actualAssociationEnds.Count(), "Should find exactly 1 AssociationEnd '{0}' in '{1}'", expectedAssociationEnd.RoleName, expectedAssociationType.FullName))
                {
                    this.CompareAssociationEnd(expectedAssociationEnd, actualAssociationEnds.Single());
                }
            }

            if (expectedAssociationType.ReferentialConstraint == null)
            {
                this.SatisfiesCondition(actualAssociationType.ReferentialConstraint == null, "Expected no referential constraint on '{0}'", expectedAssociationType.FullName);
            }
            else
            {
                if (this.SatisfiesCondition(actualAssociationType.ReferentialConstraint != null, "Expected to have referential constraint on '{0}'", expectedAssociationType.FullName))
                {
                    this.CompareReferentialConstraint(expectedAssociationType.ReferentialConstraint, actualAssociationType.ReferentialConstraint);
                }
            }
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the AssociationSet class with given name and type.
 /// </summary>
 /// <param name="name">Name of association set.</param>
 /// <param name="associationType">Type of association set elements.</param>
 public AssociationSet(string name, AssociationType associationType)
 {
     this.Name = name;
     this.AssociationType = associationType;
     this.Ends = new List<AssociationSetEnd>();
 }
        /// <summary>
        /// Visits association type
        /// </summary>
        /// <param name="association">association type to visit</param>
        protected virtual void VisitAssociationType(AssociationType association)
        {
            this.VisitAnnotatedItem(association);

            foreach (var associationEnd in association.Ends)
            {
                this.VisitAssociationEnd(associationEnd);
            }

            if (association.ReferentialConstraint != null)
            {
                this.VisitReferentialConstraint(association.ReferentialConstraint);
            }
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the AssociationSet class with given name and type.
 /// </summary>
 /// <param name="name">Name of association set.</param>
 /// <param name="associationType">Type of association set elements.</param>
 public AssociationSet(string name, AssociationType associationType)
 {
     this.Name            = name;
     this.AssociationType = associationType;
     this.Ends            = new List <AssociationSetEnd>();
 }
 private IEnumerable<XElement> GenerateAssociationEnds(AssociationType association, XNamespace xmlNamespace)
 {
     var content = from end in association.Ends
                   select this.GenerateAssociationEnd(xmlNamespace, end);
     return content;
 }
 private XElement GenerateAssociation(XNamespace xmlNamespace, AssociationType association)
 {
     return new XElement(
         xmlNamespace + "Association",
         new XAttribute("Name", association.Name),
         this.GenerateDocumentation(xmlNamespace, association),
         this.GenerateAssociationEnds(association, xmlNamespace),
         association.ReferentialConstraint == null ? null : this.GenerateReferentialConstrait(association.ReferentialConstraint, xmlNamespace),
         this.GenerateAnnotations(xmlNamespace, association));
 }