本文整理汇总了C#中System.Data.Entity.Edm.Db.DbTableMetadata.ContainsEquivalentForeignKey方法的典型用法代码示例。如果您正苦于以下问题:C# DbTableMetadata.ContainsEquivalentForeignKey方法的具体用法?C# DbTableMetadata.ContainsEquivalentForeignKey怎么用?C# DbTableMetadata.ContainsEquivalentForeignKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.Edm.Db.DbTableMetadata
的用法示例。
在下文中一共展示了DbTableMetadata.ContainsEquivalentForeignKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyForeignKeyConstraint
private static void CopyForeignKeyConstraint(
DbDatabaseMetadata database, DbTableMetadata toTable,
DbForeignKeyConstraintMetadata fk)
{
Contract.Requires(toTable != null);
Contract.Requires(fk != null);
var newFk = new DbForeignKeyConstraintMetadata
{
DeleteAction = fk.DeleteAction,
Name =
database.Schemas.Single().Tables.SelectMany(t => t.ForeignKeyConstraints).
UniquifyName(fk.Name),
PrincipalTable = fk.PrincipalTable
};
// Make sure all the dependent columns refer to columns in the newTable
SetAllDependentColumns(newFk, fk.DependentColumns, toTable.Columns);
if (!toTable.ContainsEquivalentForeignKey(newFk))
{
toTable.ForeignKeyConstraints.Add(newFk);
}
}
示例2: MoveForeignKeyConstraint
/// <summary>
/// Moves a foreign key constraint from oldTable to newTable and updates column references
/// </summary>
private static void MoveForeignKeyConstraint(
DbTableMetadata fromTable, DbTableMetadata toTable, DbForeignKeyConstraintMetadata fk)
{
Contract.Requires(fromTable != null);
Contract.Requires(toTable != null);
Contract.Requires(fk != null);
fromTable.ForeignKeyConstraints.Remove(fk);
// Only move it to the new table if the destination is not the principal table or if all dependent columns are not FKs
// Otherwise you end up with an FK from the PKs to the PKs of the same table
if (fk.PrincipalTable != toTable
||
!fk.DependentColumns.All(c => c.IsPrimaryKeyColumn))
{
// Make sure all the dependent columns refer to columns in the newTable
var oldColumns = fk.DependentColumns.ToArray();
fk.DependentColumns.Clear();
SetAllDependentColumns(fk, oldColumns, toTable.Columns);
if (!toTable.ContainsEquivalentForeignKey(fk))
{
toTable.ForeignKeyConstraints.Add(fk);
}
}
}