internal void LoadRelationships(EntityContainer entityContainer) { if (this.m_entityContainerMap.ContainsKey(entityContainer)) { return; } foreach (EntitySetBase baseEntitySet in entityContainer.BaseEntitySets) { RelationshipSet relationshipSet = baseEntitySet as RelationshipSet; if (relationshipSet != null) { RelationshipType elementType = relationshipSet.ElementType; AssociationType associationType = elementType as AssociationType; if (associationType != null && ConstraintManager.IsBinary(elementType)) { foreach (ReferentialConstraint referentialConstraint in associationType.ReferentialConstraints) { ForeignKeyConstraint foreignKeyConstraint = new ForeignKeyConstraint(relationshipSet, referentialConstraint); List <ForeignKeyConstraint> foreignKeyConstraintList; if (!this.m_parentChildRelationships.TryGetValue(foreignKeyConstraint.Pair, out foreignKeyConstraintList)) { foreignKeyConstraintList = new List <ForeignKeyConstraint>(); this.m_parentChildRelationships[foreignKeyConstraint.Pair] = foreignKeyConstraintList; } foreignKeyConstraintList.Add(foreignKeyConstraint); } } } } this.m_entityContainerMap[entityContainer] = entityContainer; }
internal ForeignKeyConstraint(RelationshipSet relationshipSet, ReferentialConstraint constraint) { var assocSet = relationshipSet as AssociationSet; var fromEnd = constraint.FromRole as AssociationEndMember; var toEnd = constraint.ToRole as AssociationEndMember; // Currently only Associations are supported if (null == assocSet || null == fromEnd || null == toEnd) { throw new NotSupportedException(); } m_constraint = constraint; var parent = MetadataHelper.GetEntitySetAtEnd(assocSet, fromEnd); // relationshipSet.GetRelationshipEndExtent(constraint.FromRole); var child = MetadataHelper.GetEntitySetAtEnd(assocSet, toEnd); // relationshipSet.GetRelationshipEndExtent(constraint.ToRole); m_extentPair = new ExtentPair(parent, child); m_childKeys = new List <string>(); foreach (var prop in constraint.ToProperties) { m_childKeys.Add(prop.Name); } m_parentKeys = new List <string>(); foreach (var prop in constraint.FromProperties) { m_parentKeys.Add(prop.Name); } PlanCompiler.Assert( (RelationshipMultiplicity.ZeroOrOne == fromEnd.RelationshipMultiplicity || RelationshipMultiplicity.One == fromEnd.RelationshipMultiplicity), "from-end of relationship constraint cannot have multiplicity greater than 1"); }
internal ForeignKeyConstraint(RelationshipSet relationshipSet, ReferentialConstraint constraint) { AssociationSet associationSet = relationshipSet as AssociationSet; AssociationEndMember fromRole = constraint.FromRole as AssociationEndMember; AssociationEndMember toRole = constraint.ToRole as AssociationEndMember; if (associationSet == null || fromRole == null || toRole == null) { throw new NotSupportedException(); } this.m_constraint = constraint; this.m_extentPair = new ExtentPair((EntitySetBase)MetadataHelper.GetEntitySetAtEnd(associationSet, fromRole), (EntitySetBase)MetadataHelper.GetEntitySetAtEnd(associationSet, toRole)); this.m_childKeys = new List <string>(); foreach (EdmMember toProperty in constraint.ToProperties) { this.m_childKeys.Add(toProperty.Name); } this.m_parentKeys = new List <string>(); foreach (EdmMember fromProperty in constraint.FromProperties) { this.m_parentKeys.Add(fromProperty.Name); } System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(fromRole.RelationshipMultiplicity == RelationshipMultiplicity.ZeroOrOne || RelationshipMultiplicity.One == fromRole.RelationshipMultiplicity, "from-end of relationship constraint cannot have multiplicity greater than 1"); }