/// <summary> /// Adds new <see cref="ForeignKey"/> to <see cref="ForeignKeys"/> collection. /// </summary> /// <param name="constraint">Constraint to add.</param> public void Add(ForeignKey constraint) { this.ForeignKeys.Add(constraint); }
private void ConvertAssociationSetsToForeignKeys(EntityContainer container, Dictionary<EntitySet, Table> entitySetToTable) { foreach (AssociationSet associationSet in container.AssociationSets) { var assoc = associationSet.AssociationType; var referentialConstraint = assoc.ReferentialConstraint; ExceptionUtilities.Assert(referentialConstraint != null, "S-space associations must have RI constraints"); var dependentSet = associationSet.Ends.Single(c => c.AssociationEnd == referentialConstraint.DependentAssociationEnd).EntitySet; var principalSet = associationSet.Ends.Single(c => c.AssociationEnd == referentialConstraint.PrincipalAssociationEnd).EntitySet; var principalTable = entitySetToTable[principalSet]; var dependentTable = entitySetToTable[dependentSet]; var fk = new ForeignKey(container.Name, associationSet.Name); fk.Target = principalTable; fk.Schema = dependentTable.Schema; foreach (var prop in referentialConstraint.DependentProperties) { var dependentColumn = dependentTable.Columns.Single(c => c.Name == prop.Name); fk.SourceColumns.Add(dependentColumn); } foreach (var prop in referentialConstraint.PrincipalProperties) { var principalColumn = principalTable.Columns.Single(c => c.Name == prop.Name); fk.TargetColumns.Add(principalColumn); } dependentTable.ForeignKeys.Add(fk); } }