コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RelationshipType"/> class.
        /// </summary>
        /// <param name="associationSet">The <see cref="AssociationSet"/> to wrap.</param>
        internal RelationshipType(AssociationSet associationSet)
        {
            this.AssociationSet = associationSet;
            this.AssociationType = associationSet.AssociationType;
            this.ReferentialConstraint = this.AssociationType.ReferentialConstraint;
            this.IsIdentifyingRelationship = this.ReferentialConstraint != null &&
                                             this.ReferentialConstraint.DependentProperties.All(p => p.IsPrimaryKey);
            var sides = this.AssociationSet.Ends.Select(e => new RelationshipSide(e, this)).ToList();

            sides[0].OtherSide = sides[1];
            sides[1].OtherSide = sides[0];

            this.Sides = sides.AsReadOnly();

            this.DetermineMultiplicity();

            if (this.ReferentialConstraint != null)
            {
                this.DependentSide = this.Side(rs => rs.FromAssociationEnd == this.ReferentialConstraint.DependentAssociationEnd);
                this.PrincipalSide = this.Side(rs => rs.FromAssociationEnd == this.ReferentialConstraint.PrincipalAssociationEnd);

                this.DependentProperties = this.ReferentialConstraint.DependentProperties.ToList().AsReadOnly();
                this.PrincipalProperties = this.ReferentialConstraint.PrincipalProperties.ToList().AsReadOnly();
            }
            else
            {
                this.DependentProperties = new List<MemberProperty>().AsReadOnly();
                this.PrincipalProperties = new List<MemberProperty>().AsReadOnly();
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RelationshipDescription"/> class.
 /// </summary>
 /// <param name="associationSet">The association set.</param>
 /// <param name="from">EntityDataKey for the 'from' end.</param>
 /// <param name="toRoleName">Role name for the 'to' end</param>
 /// <param name="to">EntityDataKey for the 'to' end.</param>
 public RelationshipDescription(AssociationSet associationSet, EntityDataKey from, string toRoleName, EntityDataKey to)
 {
     this.AssociationSet = associationSet;
     this.From = from;
     this.ToRoleName = toRoleName;
     this.To = to;
     this.FromRoleName = this.AssociationSet.Ends.Where(e => e.AssociationEnd.RoleName != toRoleName).Single().AssociationEnd.RoleName;
 }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RelationshipGroupEnd"/> class.
        /// </summary>
        /// <param name="associationSet">The association set.</param>
        /// <param name="associationSetEnd">The association set end.</param>
        public RelationshipGroupEnd(AssociationSet associationSet, AssociationSetEnd associationSetEnd)
        {
            this.EntitySet = associationSetEnd.EntitySet;
            this.EntityType = associationSetEnd.AssociationEnd.EntityType;
            this.Multiplicity = associationSet.GetOtherEnd(associationSetEnd).AssociationEnd.Multiplicity;

            this.associationSetEnds = new List<KeyValuePair<AssociationSet, AssociationSetEnd>>();
            this.associationSetEnds.Add(new KeyValuePair<AssociationSet, AssociationSetEnd>(associationSet, associationSetEnd));
            this.Candidates = new List<RelationshipCandidate>();

            this.CapacitySelector = CapacityRangeSelector.GetDefaultCapacityRangeSelector(this.Multiplicity);
        }
コード例 #4
0
 /// <summary>
 /// Removes an <see cref="AssociationSet" /> from <see cref="AssociationSets" /> collection.
 /// </summary>
 /// <param name="associationSet">Association set to remove.</param>
 public void Remove(AssociationSet associationSet)
 {
     ExceptionUtilities.CheckArgumentNotNull(associationSet, "associationSet");
     ExceptionUtilities.Assert(associationSet.Container == this, "Association set was not added to this container");
     ExceptionUtilities.Assert(this.associationSetsList.Remove(associationSet), "Association set was not added to this model");
     associationSet.Container = null;
 }
コード例 #5
0
 /// <summary>
 /// Adds an <see cref="AssociationSet" /> to <see cref="AssociationSets" /> collection.
 /// </summary>
 /// <param name="associationSet">Association set to add.</param>
 public void Add(AssociationSet associationSet)
 {
     ExceptionUtilities.CheckArgumentNotNull(associationSet, "associationSet");
     ExceptionUtilities.Assert(associationSet.Container == null, "Association set was already added to another container");
     associationSet.Container = this;
     this.associationSetsList.Add(associationSet);
 }
コード例 #6
0
        private bool HasOverlappingForeignKeys(AssociationSet associationSet)
        {
            if (associationSet.AssociationType.ReferentialConstraint == null)
            {
                return false;
            }

            foreach (MemberProperty dependentProperty in associationSet.AssociationType.ReferentialConstraint.DependentProperties)
            {
                if (this.entityContainer.Model.Associations.Any(a => a.ReferentialConstraint != null && 
                        a != associationSet.AssociationType && 
                        a.ReferentialConstraint.DependentProperties.Contains(dependentProperty)))
                {
                    return true;
                }
            }

            return false;
        }
コード例 #7
0
        private List<KeyValuePair<AssociationSet, AssociationSetEnd>> GetAllDependentEndsFromIdentifyingGroup(AssociationSet associationSet)
        {
            List<KeyValuePair<AssociationSet, AssociationSetEnd>> result = new List<KeyValuePair<AssociationSet, AssociationSetEnd>>();

            if (associationSet.AssociationType.ReferentialConstraint == null ||
                !associationSet.AssociationType.ReferentialConstraint.DependentProperties.Any(p => p.IsPrimaryKey))
            {
                // not part of identifying relationship group.
                return result;
            }

            AssociationEnd dependentEnd = associationSet.AssociationType.ReferentialConstraint.DependentAssociationEnd;
            EntitySet dependentEntitySet = associationSet.Ends.Where(e => e.AssociationEnd == dependentEnd).Single().EntitySet;
            
            List<MemberProperty> primaryKeysWhichAreForeignKeys = new List<MemberProperty>();

            foreach (AssociationSet assocSet in this.EntityContainer.AssociationSets.Where(s => s.AssociationType.ReferentialConstraint != null))
            {
                ReferentialConstraint rc = assocSet.AssociationType.ReferentialConstraint;
                AssociationSetEnd dependentSetEnd = assocSet.Ends.Where(e => e.AssociationEnd == rc.DependentAssociationEnd).Single();
                if (dependentEnd.EntityType.IsKindOf(rc.DependentAssociationEnd.EntityType) && dependentSetEnd.EntitySet == dependentEntitySet)
                {
                    var dependentPrimaryKeys = rc.DependentProperties.Where(p => p.IsPrimaryKey).ToList();

                    if (dependentPrimaryKeys.Count > 0)
                    {
                        primaryKeysWhichAreForeignKeys.AddRange(dependentPrimaryKeys);
                        result.Add(new KeyValuePair<AssociationSet, AssociationSetEnd>(assocSet, dependentSetEnd));
                    }
                }
            }

            int primaryKeysCount = dependentEnd.EntityType.AllKeyProperties.Count();

            if (primaryKeysWhichAreForeignKeys.Count != primaryKeysCount)
            {
                // Not identifying or overlapping.
                result.Clear();
            }

            return result;
        }
コード例 #8
0
        /// <summary>
        /// Sets the capacity range selector for the specified association set and end.
        /// </summary>
        /// <param name="associationSet">The association set.</param>
        /// <param name="associationSetEnd">The association set end.</param>
        /// <param name="selector">The capacity range selector.</param>
        public void SetCapacityRangeSelector(AssociationSet associationSet, AssociationSetEnd associationSetEnd, Func<CapacityRange> selector)
        {
            ExceptionUtilities.CheckArgumentNotNull(associationSet, "associationSet");
            ExceptionUtilities.CheckArgumentNotNull(associationSetEnd, "associationSetEnd");

            this.SetCapacityRangeSelector(associationSet.Name, associationSetEnd.AssociationEnd.RoleName, selector);
        }
コード例 #9
0
        private void CompareAssociationSet(AssociationSet expectedAssociationSet, AssociationSet actualAssociationSet)
        {
            foreach (AssociationSetEnd expectedEnd in expectedAssociationSet.Ends)
            {
                List<AssociationSetEnd> associationSetEnds = actualAssociationSet.Ends.Where(asEnd => asEnd.AssociationEnd.RoleName == expectedEnd.AssociationEnd.RoleName).ToList();
                if (!this.WriteErrorIfFalse(associationSetEnds.Count == 1, "Cannot find associationSetEnd '{0}' ", expectedEnd.AssociationEnd.RoleName))
                {
                    this.CompareAssociationSetEnd(expectedEnd, associationSetEnds.Single());
                }
            }

            this.CompareAssociationType(expectedAssociationSet.AssociationType, actualAssociationSet.AssociationType);
        }
コード例 #10
0
ファイル: XsdlParserBase.cs プロジェクト: larsenjo/odata.net
        private AssociationSet ParseAssociationSet(XElement associationSetElement)
        {
            string associationSetName = associationSetElement.GetRequiredAttributeValue("Name");

            string associationTypeNamespace = this.ParseEdmTypeName(associationSetElement.GetRequiredAttributeValue("Association"))[0];
            string associationTypeName = this.ParseEdmTypeName(associationSetElement.GetRequiredAttributeValue("Association"))[1];

            var associationSet = new AssociationSet(associationSetName, new AssociationTypeReference(associationTypeNamespace, associationTypeName));

            foreach (var associationSetEndElement in associationSetElement.Elements().Where(el => this.IsXsdlElement(el, "End")))
            {
                associationSet.Ends.Add(this.ParseAssociationSetEnd(associationSetEndElement));
            }

            this.ParseAnnotations(associationSet, associationSetElement);
            return associationSet;
        }
コード例 #11
0
        private void CompareAssociationSet(AssociationSet expectedAssociationSet, AssociationSet actualAssociationSet)
        {
            this.SatisfiesEquals(
                expectedAssociationSet.AssociationType.FullName,
                actualAssociationSet.AssociationType.FullName,
                "Association type name not match for AssociationSet '{0}'.",
                expectedAssociationSet.Name);

            foreach (AssociationSetEnd expectedEnd in expectedAssociationSet.Ends)
            {
                var actualAssociationSetEnds = actualAssociationSet.Ends.Where(asEnd => asEnd.AssociationEnd.RoleName == expectedEnd.AssociationEnd.RoleName);
                if (this.SatisfiesEquals(1, actualAssociationSetEnds.Count(), "Should find exactly 1 associationSetEnd '{0}' ", expectedEnd.AssociationEnd.RoleName))
                {
                    var actualAssociationSetEnd = actualAssociationSetEnds.Single();
                    this.CompareAssociationSetEnd(expectedEnd, actualAssociationSetEnd);
                    this.CompareAnnotations(expectedEnd.Annotations, actualAssociationSetEnd.Annotations);
                }
            }
        }
コード例 #12
0
ファイル: CsdlParser.cs プロジェクト: larsenjo/odata.net
        private void CloneContainerContents(EntityContainer baseContainer, EntityContainer extendedContainer)
        {
            foreach (var entitySet in baseContainer.EntitySets)
            {
                var clonedEntitySet = new EntitySet(entitySet.Name, entitySet.EntityType);
                extendedContainer.Add(clonedEntitySet);
            }

            foreach (var associationSet in baseContainer.AssociationSets)
            {
                var clonedAssociationSet = new AssociationSet(associationSet.Name, associationSet.AssociationType);
                foreach (var setEnd in associationSet.Ends)
                {
                    clonedAssociationSet.Add(new AssociationSetEnd(setEnd.AssociationEnd, setEnd.EntitySet.Name));
                }

                extendedContainer.Add(clonedAssociationSet);
            }

            foreach (var functionImport in baseContainer.FunctionImports)
            {
                var clonedFunctionImport = new FunctionImport(functionImport.Name);
                foreach (var returnType in functionImport.ReturnTypes)
                {
                    clonedFunctionImport.ReturnTypes.Add(returnType);
                }

                foreach (var parameter in functionImport.Parameters)
                {
                    clonedFunctionImport.Add(new FunctionParameter(parameter.Name, parameter.DataType, parameter.Mode));
                }

                extendedContainer.Add(clonedFunctionImport);
            }
        }
コード例 #13
0
            /// <summary>
            /// Initializes a new instance of the <see cref="PropertyConstraint"/> class.
            /// </summary>
            /// <param name="associationSet">The association set.</param>
            /// <param name="ordinal">The ordinal of the constraint in the <see cref="ReferentialConstraint"/> for the association set.</param>
            public PropertyConstraint(AssociationSet associationSet, int ordinal)
            {
                this.AssociationSet = associationSet;
                this.ordinal = ordinal;

                AssociationSetEnd principalEnd = associationSet.Ends.Where(e => e.AssociationEnd == associationSet.AssociationType.ReferentialConstraint.PrincipalAssociationEnd).Single();
                
                this.PrincipalEntitySet = principalEnd.EntitySet;
                this.DependentEntitySet = associationSet.GetOtherEnd(principalEnd).EntitySet;
            }
コード例 #14
0
        /// <summary>
        /// Visit association set
        /// </summary>
        /// <param name="associationSet">association set to visit</param>
        protected virtual void VisitAssociationSet(AssociationSet associationSet)
        {
            this.VisitAnnotatedItem(associationSet);

            foreach (var associationSetEnd in associationSet.Ends)
            {
                this.VisitAssociationSetEnd(associationSetEnd);
            }
        }
コード例 #15
0
 private IEnumerable<XElement> GenerateAssociationSetEnds(XNamespace xmlNamespace, AssociationSet associationSet)
 {
     var content = from setEnd in associationSet.Ends
                   select this.GenerateAssociationSetEnd(xmlNamespace, setEnd);
     return content;
 }
コード例 #16
0
 private XElement GenerateAssociationSet(XNamespace xmlNamespace, AssociationSet associationSet)
 {
     return new XElement(
         xmlNamespace + "AssociationSet",
         new XAttribute("Name", associationSet.Name),
         new XAttribute("Association", this.GetFullyQualifiedName(associationSet.AssociationType)),
         this.GenerateDocumentation(xmlNamespace, associationSet),
         this.GenerateAssociationSetEnds(xmlNamespace, associationSet),
         this.GenerateAnnotations(xmlNamespace, associationSet));
 }