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


C# Relation.GetRelationFkColumnName方法代码示例

本文整理汇总了C#中Relation.GetRelationFkColumnName方法的典型用法代码示例。如果您正苦于以下问题:C# Relation.GetRelationFkColumnName方法的具体用法?C# Relation.GetRelationFkColumnName怎么用?C# Relation.GetRelationFkColumnName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Relation的用法示例。


在下文中一共展示了Relation.GetRelationFkColumnName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoChangeRelationType_from_n_m_to_1_1

        public void DoChangeRelationType_from_n_m_to_1_1(Relation rel)
        {
            string destAssocName = rel.GetAssociationName();
            var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);

            var srcTblName = db.GetTableName(saved.Module.SchemaName, saved.GetRelationTableName());

            // Drop relations first as 1:1 and n:m relations share the same names
            var srcAssocA = saved.GetRelationAssociationName(RelationEndRole.A);
            if (db.CheckFKConstraintExists(srcTblName, srcAssocA))
                db.DropFKConstraint(srcTblName, srcAssocA);
            var srcAssocB = saved.GetRelationAssociationName(RelationEndRole.B);
            if (db.CheckFKConstraintExists(srcTblName, srcAssocB))
                db.DropFKConstraint(srcTblName, srcAssocB);

            DoNew_1_1_Relation(rel);

            if (rel.HasStorage(RelationEndRole.A))
            {
                var destTblName = db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName);
                var destColName = Construct.ForeignKeyColumnName(rel.B);
                var srcColName = rel.GetRelationFkColumnName(RelationEndRole.B);
                var srcFKColName = rel.GetRelationFkColumnName(RelationEndRole.A);

                if (!db.CheckFKColumnContainsUniqueValues(srcTblName, srcColName))
                {
                    Log.ErrorFormat("Unable to change Relation '{0}' from n:m to 1:1. Data is not unique", destAssocName);
                    return;
                }
                db.CopyFKs(srcTblName, srcColName, destTblName, destColName, srcFKColName);
            }
            if (rel.HasStorage(RelationEndRole.B))
            {
                var destTblName = db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName);
                var destColName = Construct.ForeignKeyColumnName(rel.A);
                var srcColName = rel.GetRelationFkColumnName(RelationEndRole.A);
                var srcFKColName = rel.GetRelationFkColumnName(RelationEndRole.B);

                if (!db.CheckFKColumnContainsUniqueValues(srcTblName, srcColName))
                {
                    Log.ErrorFormat("Unable to change Relation '{0}' from n:m to 1:1. Data is not unique", destAssocName);
                    return;
                }
                db.CopyFKs(srcTblName, srcColName, destTblName, destColName, srcFKColName);
            }

            if (db.CheckTableExists(srcTblName))
                db.DropTable(srcTblName);
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:49,代码来源:Cases.cs

示例2: DoChangeRelationType_from_1_1_to_n_m

        public void DoChangeRelationType_from_1_1_to_n_m(Relation rel)
        {
            var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
            string srcAssocName = saved.GetAssociationName();

            RelationEnd relEnd, otherEnd;

            switch (saved.Storage)
            {
                case StorageType.Replicate:
                case StorageType.MergeIntoA:
                    relEnd = saved.A;
                    otherEnd = saved.B;
                    break;
                case StorageType.MergeIntoB:
                    otherEnd = saved.A;
                    relEnd = saved.B;
                    break;
                default:
                    Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", srcAssocName, rel.Storage);
                    return;
            }

            var srcTblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
            var srcColName = Construct.ForeignKeyColumnName(otherEnd);

            var destTbl = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
            var destCol = rel.GetRelationFkColumnName(relEnd.GetRole());
            var destFKCol = rel.GetRelationFkColumnName(otherEnd.GetRole());

            // Drop relations first as 1:1 and n:m relations share the same names
            var srcAssocA = saved.GetRelationAssociationName(RelationEndRole.A);
            if (db.CheckFKConstraintExists(db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), srcAssocA))
                db.DropFKConstraint(db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), srcAssocA);
            var srcAssocB = saved.GetRelationAssociationName(RelationEndRole.B);
            if (db.CheckFKConstraintExists(db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), srcAssocB))
                db.DropFKConstraint(db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), srcAssocB);

            DoNew_N_M_Relation(rel);
            db.InsertFKs(srcTblName, srcColName, destTbl, destCol, destFKCol);

            // Drop columns
            if (saved.Storage == StorageType.MergeIntoA || saved.Storage == StorageType.Replicate)
            {
                if (db.CheckColumnExists(db.GetTableName(saved.A.Type.Module.SchemaName, saved.A.Type.TableName), Construct.ForeignKeyColumnName(saved.B)))
                    db.DropColumn(db.GetTableName(saved.A.Type.Module.SchemaName, saved.A.Type.TableName), Construct.ForeignKeyColumnName(saved.B));
            }
            if (saved.Storage == StorageType.MergeIntoB || saved.Storage == StorageType.Replicate)
            {
                if (db.CheckColumnExists(db.GetTableName(saved.B.Type.Module.SchemaName, saved.B.Type.TableName), Construct.ForeignKeyColumnName(saved.A)))
                    db.DropColumn(db.GetTableName(saved.B.Type.Module.SchemaName, saved.B.Type.TableName), Construct.ForeignKeyColumnName(saved.A));
            }
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:53,代码来源:Cases.cs

示例3: DoChangeRelationType_from_1_n_to_n_m

        public void DoChangeRelationType_from_1_n_to_n_m(Relation rel)
        {
            string srcAssocName = rel.GetAssociationName();
            var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);

            RelationEnd relEnd, otherEnd;

            switch (saved.Storage)
            {
                case StorageType.MergeIntoA:
                    relEnd = saved.A;
                    otherEnd = saved.B;
                    break;
                case StorageType.MergeIntoB:
                    otherEnd = saved.A;
                    relEnd = saved.B;
                    break;
                default:
                    Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", srcAssocName, rel.Storage);
                    return;
            }

            var srcTblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
            var srcColName = Construct.ForeignKeyColumnName(otherEnd);

            var destTbl = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
            var destCol = rel.GetRelationFkColumnName(relEnd.GetRole());
            var destFKCol = rel.GetRelationFkColumnName(otherEnd.GetRole());

            DoNew_N_M_Relation(rel);
            db.InsertFKs(srcTblName, srcColName, destTbl, destCol, destFKCol);
            DoDelete_1_N_Relation(saved);
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:33,代码来源:Cases.cs

示例4: DoChangeRelationName

        public void DoChangeRelationName(Relation rel)
        {
            var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);

            var fkAName = saved.GetRelationFkColumnName(RelationEndRole.A);
            var fkBName = saved.GetRelationFkColumnName(RelationEndRole.B);

            if (rel.GetRelationType() == RelationType.n_m)
            {
                var srcRelTbl = db.GetTableName(saved.Module.SchemaName, saved.GetRelationTableName());
                var destRelTbl = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());

                db.RenameFKConstraint(srcRelTbl, saved.GetRelationAssociationName(RelationEndRole.A),
                    db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), fkAName, rel.GetRelationAssociationName(RelationEndRole.A), false);
                db.RenameFKConstraint(srcRelTbl, saved.GetRelationAssociationName(RelationEndRole.B),
                    db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), fkBName, rel.GetRelationAssociationName(RelationEndRole.B), false);

                db.RenameTable(srcRelTbl, destRelTbl);

                db.RenameColumn(destRelTbl, saved.GetRelationFkColumnName(RelationEndRole.A), rel.GetRelationFkColumnName(RelationEndRole.A));
                db.RenameColumn(destRelTbl, saved.GetRelationFkColumnName(RelationEndRole.B), rel.GetRelationFkColumnName(RelationEndRole.B));
            }
            else if (rel.GetRelationType() == RelationType.one_n)
            {
                if (saved.HasStorage(RelationEndRole.A) &&
                    Construct.ForeignKeyColumnName(saved.B) != Construct.ForeignKeyColumnName(rel.B))
                {
                    var tbl = db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName);
                    db.RenameFKConstraint(tbl, saved.GetAssociationName(),
                        db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), fkAName, rel.GetAssociationName(), false);
                    db.RenameColumn(tbl, Construct.ForeignKeyColumnName(saved.B), Construct.ForeignKeyColumnName(rel.B));
                }
                else if (saved.HasStorage(RelationEndRole.B) &&
                    Construct.ForeignKeyColumnName(saved.A) != Construct.ForeignKeyColumnName(rel.A))
                {
                    var tbl = db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName);
                    db.RenameFKConstraint(tbl, saved.GetAssociationName(),
                        db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), fkBName, rel.GetAssociationName(), false);
                    db.RenameColumn(tbl, Construct.ForeignKeyColumnName(saved.A), Construct.ForeignKeyColumnName(rel.A));
                }
            }
            else if (rel.GetRelationType() == RelationType.one_one)
            {
                if (saved.HasStorage(RelationEndRole.A))
                {
                    var tbl = db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName);
                    db.RenameFKConstraint(tbl, saved.GetRelationAssociationName(RelationEndRole.A),
                        db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), fkAName, rel.GetRelationAssociationName(RelationEndRole.A), false);
                    if (Construct.ForeignKeyColumnName(saved.B) != Construct.ForeignKeyColumnName(rel.B))
                    {
                        db.RenameColumn(tbl, Construct.ForeignKeyColumnName(saved.B), Construct.ForeignKeyColumnName(rel.B));
                    }
                }
                if (saved.HasStorage(RelationEndRole.B))
                {
                    var tbl = db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName);
                    db.RenameFKConstraint(tbl, saved.GetRelationAssociationName(RelationEndRole.B),
                        db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), fkBName, rel.GetRelationAssociationName(RelationEndRole.B), false);
                    if (Construct.ForeignKeyColumnName(saved.A) != Construct.ForeignKeyColumnName(rel.A))
                    {
                        db.RenameColumn(tbl, Construct.ForeignKeyColumnName(saved.A), Construct.ForeignKeyColumnName(rel.A));
                    }
                }
            }
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:65,代码来源:Cases.cs

示例5: Do_N_M_RelationChange_FromNotIndexed_To_Indexed

        public void Do_N_M_RelationChange_FromNotIndexed_To_Indexed(Relation rel, RelationEndRole role)
        {
            string assocName = rel.GetAssociationName();
            Log.InfoFormat("Create N:M Relation {1} PositionStorage: {0}", assocName, role);

            var tblName = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
            var fkName = rel.GetRelationFkColumnName(role);

            db.CreateColumn(tblName, fkName + Zetbox.API.Helper.PositionSuffix, System.Data.DbType.Int32, 0, 0, true);
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:10,代码来源:Cases.cs

示例6: Do_N_M_RelationChange_FromIndexed_To_NotIndexed

        public void Do_N_M_RelationChange_FromIndexed_To_NotIndexed(Relation rel, RelationEndRole role)
        {
            string assocName = rel.GetAssociationName();
            Log.InfoFormat("Drop N:M Relation {1} PositionStorage: {0}", assocName, role);

            var tblName = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
            var fkName = rel.GetRelationFkColumnName(role);

            if (db.CheckColumnExists(tblName, fkName + Zetbox.API.Helper.PositionSuffix))
                db.DropColumn(tblName, fkName + Zetbox.API.Helper.PositionSuffix);
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:11,代码来源:Cases.cs

示例7: DoNew_N_M_Relation

        public void DoNew_N_M_Relation(Relation rel)
        {
            string assocName = rel.GetAssociationName();
            Log.InfoFormat("New N:M Relation: {0}", assocName);

            var tblName = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
            var fkAName = rel.GetRelationFkColumnName(RelationEndRole.A);
            var fkBName = rel.GetRelationFkColumnName(RelationEndRole.B);

            if (db.CheckTableExists(tblName))
            {
                Log.ErrorFormat("Relation table {0} already exists", tblName);
                return;
            }

            db.CreateTable(tblName, true);

            db.CreateColumn(tblName, fkAName, System.Data.DbType.Int32, 0, 0, false);
            if (rel.NeedsPositionStorage(RelationEndRole.A))
            {
                db.CreateColumn(tblName, fkAName + Zetbox.API.Helper.PositionSuffix, System.Data.DbType.Int32, 0, 0, true);
            }

            db.CreateColumn(tblName, fkBName, System.Data.DbType.Int32, 0, 0, false);
            if (rel.NeedsPositionStorage(RelationEndRole.B))
            {
                db.CreateColumn(tblName, fkBName + Zetbox.API.Helper.PositionSuffix, System.Data.DbType.Int32, 0, 0, true);
            }

            if (rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable())
            {
                db.CreateColumn(tblName, "ExportGuid", System.Data.DbType.Guid, 0, 0, false, new NewGuidDefaultConstraint());
            }

            db.CreateFKConstraint(tblName, db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), fkAName, rel.GetRelationAssociationName(RelationEndRole.A), false);
            db.CreateIndex(tblName, Construct.IndexName(tblName.Name, fkAName), false, false, fkAName);
            db.CreateFKConstraint(tblName, db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), fkBName, rel.GetRelationAssociationName(RelationEndRole.B), false);
            db.CreateIndex(tblName, Construct.IndexName(tblName.Name, fkBName), false, false, fkBName);
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:39,代码来源:Cases.cs

示例8: Check_N_M_RelationColumns

        private void Check_N_M_RelationColumns(Relation rel)
        {
            string assocName = rel.GetAssociationName();

            var tblName = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
            string fkAName = rel.GetRelationFkColumnName(RelationEndRole.A);
            string fkBName = rel.GetRelationFkColumnName(RelationEndRole.B);
            string assocAName = rel.GetRelationAssociationName(RelationEndRole.A);
            string assocBName = rel.GetRelationAssociationName(RelationEndRole.B);
            string fkAIndex = fkAName + Zetbox.API.Helper.PositionSuffix;
            string fkBIndex = fkBName + Zetbox.API.Helper.PositionSuffix;

            Log.DebugFormat("Checking [{0}]", assocName);

            if (!db.CheckTableExists(tblName))
            {
                Log.WarnFormat("Relation table '{0}' is missing for [{1}]", tblName, assocName);
                if (repair)
                {
                    Case.DoNew_N_M_Relation(rel);
                }
                return;
            }
            CheckColumn(tblName, fkAName, System.Data.DbType.Int32, 0, 0, false, null);
            CheckColumn(tblName, fkBName, System.Data.DbType.Int32, 0, 0, false, null);

            if (!db.CheckFKConstraintExists(tblName, assocAName))
            {
                Log.WarnFormat("FK Constraint '{0}' for A is missing for [{1}]", assocAName, assocName);
                if (repair)
                {
                    db.CreateFKConstraint(tblName, db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), fkAName, assocAName, true);
                }
            }
            if (!db.CheckFKConstraintExists(tblName, assocBName))
            {
                Log.WarnFormat("FK Constraint '{0}' for B is missing for [{1}]", assocBName, assocName);
                if (repair)
                {
                    db.CreateFKConstraint(tblName, db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), fkBName, assocBName, true);
                }
            }

            if (!db.CheckIndexExists(tblName, Construct.IndexName(tblName.Name, fkAName)))
            {
                Log.WarnFormat("Index '{0}' is missing", Construct.IndexName(tblName.Name, fkAName));
                if (repair)
                {
                    db.CreateIndex(tblName, Construct.IndexName(tblName.Name, fkAName), false, false, fkAName);
                }
            }
            if (!db.CheckIndexExists(tblName, Construct.IndexName(tblName.Name, fkBName)))
            {
                Log.WarnFormat("Index '{0}' is missing", Construct.IndexName(tblName.Name, fkBName));
                if (repair)
                {
                    db.CreateIndex(tblName, Construct.IndexName(tblName.Name, fkBName), false, false, fkBName);
                }
            }

            if (rel.NeedsPositionStorage(RelationEndRole.A))
            {
                CheckColumn(tblName, fkAIndex, System.Data.DbType.Int32, 0, 0, true, null);
                if (repair)
                {
                    // TODO: Call case
                }
            }
            if (!rel.NeedsPositionStorage(RelationEndRole.A) && db.CheckColumnExists(tblName, fkAIndex))
            {
                Log.WarnFormat("Navigator A '{0}' Index Column exists but property is not indexed for [{1}]", fkAName, assocName);
                if (repair)
                {
                    // TODO: Call case
                }
            }

            if (rel.NeedsPositionStorage(RelationEndRole.B))
            {
                CheckColumn(tblName, fkBIndex, System.Data.DbType.Int32, 0, 0, true, null);
                if (repair)
                {
                    // TODO: Call case
                }
            }
            if (!rel.NeedsPositionStorage(RelationEndRole.B) && db.CheckColumnExists(tblName, fkBIndex))
            {
                Log.WarnFormat("Navigator B '{0}' Index Column exists but property is not indexed for [{1}]", fkBName, assocName);
                if (repair)
                {
                    // TODO: Call case
                }
            }

            if (rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable())
            {
                CheckColumn(tblName, "ExportGuid", System.Data.DbType.Guid, 0, 0, false, new NewGuidDefaultConstraint());
            }
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:99,代码来源:SchemaManager.CheckSchema.cs


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