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"); }
/// <summary> /// Is there a parent child relationship between table1 and table2 ? /// </summary> /// <param name="table1"> parent table ? </param> /// <param name="table2"> child table ? </param> /// <param name="constraints"> list of constraints ? </param> /// <returns> true if there is at least one constraint </returns> internal bool IsParentChildRelationship( md.EntitySetBase table1, md.EntitySetBase table2, out List<ForeignKeyConstraint> constraints) { LoadRelationships(table1.EntityContainer); LoadRelationships(table2.EntityContainer); var extentPair = new ExtentPair(table1, table2); return m_parentChildRelationships.TryGetValue(extentPair, out constraints); }
public override bool Equals(object obj) { ExtentPair extentPair = obj as ExtentPair; if (extentPair != null && extentPair.Left.Equals((object)this.Left)) { return(extentPair.Right.Equals((object)this.Right)); } return(false); }
// <summary> // Is there a parent child relationship between table1 and table2 ? // </summary> // <param name="table1"> parent table ? </param> // <param name="table2"> child table ? </param> // <param name="constraints"> list of constraints ? </param> // <returns> true if there is at least one constraint </returns> internal bool IsParentChildRelationship( md.EntitySetBase table1, md.EntitySetBase table2, out List <ForeignKeyConstraint> constraints) { LoadRelationships(table1.EntityContainer); LoadRelationships(table2.EntityContainer); var extentPair = new ExtentPair(table1, table2); return(m_parentChildRelationships.TryGetValue(extentPair, out constraints)); }
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"); }