当前位置: 首页>>代码示例>>C#>>正文


C# DbTableMetadata.ContainsEquivalentForeignKey方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:24,代码来源:EntityMappingTransformer.cs

示例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);
                }
            }
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:29,代码来源:EntityMappingTransformer.cs


注:本文中的System.Data.Entity.Edm.Db.DbTableMetadata.ContainsEquivalentForeignKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。