本文整理汇总了C#中Relation.GetRelationTableName方法的典型用法代码示例。如果您正苦于以下问题:C# Relation.GetRelationTableName方法的具体用法?C# Relation.GetRelationTableName怎么用?C# Relation.GetRelationTableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relation
的用法示例。
在下文中一共展示了Relation.GetRelationTableName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyNMProperty
private void ApplyNMProperty(
Relation rel, RelationEnd relEnd, RelationEnd otherEnd,
ObjectReferenceProperty prop)
{
this.WriteLine(" <!-- NMProperty -->");
this.WriteLine(" <!-- rel={0} -->", rel.GetRelationClassName());
this.WriteLine(" <!-- relEnd={0} otherEnd={1} -->", relEnd.RoleName, otherEnd.RoleName);
string nameAttr = String.Format("name=\"{0}\"", prop.Name);
string tableName = rel.GetRelationTableName();
string tableAttr = String.Format("table=\"`{0}`\"", tableName);
string relationEntryClassAttr = String.Format("class=\"{0}.{1}{2}+{1}Proxy,Zetbox.Objects.NHibernateImpl\"",
rel.Module.Namespace,
rel.GetRelationClassName(),
ImplementationSuffix);
string fkThisColumnAttr = String.Format("column=\"`{0}`\"", Construct.ForeignKeyColumnName(relEnd));
//string fkOtherColumnAttr = String.Format("column=\"`{0}`\"", Construct.ForeignKeyColumnName(otherEnd));
// always map as set, the wrapper has to translate/order the elements
this.WriteObjects(" <set ", nameAttr, " ", tableAttr, " inverse=\"true\" cascade=\"all-delete-orphan\" batch-size=\"100\" ");
if (prop.EagerLoading)
{
// TODO: re-think and re-test eagerloading
//this.WriteObjects("lazy=\"false\" fetch=\"join\" ");
}
this.WriteLine(">");
this.WriteObjects(" <key ", fkThisColumnAttr, " />");
this.WriteLine();
this.WriteObjects(" <one-to-many ", relationEntryClassAttr, " />");
this.WriteLine();
this.WriteObjects(" </set>");
this.WriteLine();
}
示例2: 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 = Construct.ForeignKeyColumnName(rel.A);
string fkBName = Construct.ForeignKeyColumnName(rel.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, rel.A.Type.GetTableRef(db), 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, rel.B.Type.GetTableRef(db), 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());
}
}
示例3: SecurityRulesUpdateRightsTriggerName
public static string SecurityRulesUpdateRightsTriggerName(Relation rel)
{
if (rel == null) { throw new ArgumentNullException("rel"); }
return rel.GetRelationTableName() + "_Update_Rights_Trigger";
}
示例4: 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);
}
示例5: DoCreateUpdateRightsTrigger
public void DoCreateUpdateRightsTrigger(Relation rel)
{
var updateRightsTriggerName = Construct.SecurityRulesUpdateRightsTriggerName(rel);
var tblName = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
if (db.CheckTriggerExists(tblName, updateRightsTriggerName))
db.DropTrigger(tblName, updateRightsTriggerName);
var tblList = new List<RightsTrigger>();
// Get all ObjectClasses that depends on current relation
var list = schema.GetQuery<ObjectClass>()
.Where(o => o.AccessControlList.OfType<RoleMembership>()
.Where(rm => rm.Relations
.Where(r => r == rel).Count() > 0).Count() > 0)
.Distinct().ToList().Where(o => o.NeedsRightsTable());
foreach (var dep in list)
{
Log.DebugFormat(" Additional update Table: {0}", dep.TableName);
foreach (var ac in dep.AccessControlList.OfType<RoleMembership>())
{
if (ac.Relations.Contains(rel))
{
var rt = new RightsTrigger()
{
TblName = db.GetTableName(dep.Module.SchemaName, dep.TableName),
TblNameRights = db.GetTableName(dep.Module.SchemaName, Construct.SecurityRulesTableName(dep)),
ViewUnmaterializedName = db.GetTableName(dep.Module.SchemaName, Construct.SecurityRulesRightsViewUnmaterializedName(dep)),
};
try
{
// Ignore last one - this is our n:m end
var joinList = SchemaManager.CreateJoinList(db, dep, ac.Relations, rel);
rt.Relations.AddRange(joinList.Take(joinList.Count - 1));
}
catch (Zetbox.Server.SchemaManagement.SchemaManager.JoinListException ex)
{
Log.Warn("Unable to create UpdateRightsTrigger on " + rel, ex);
return;
}
tblList.Add(rt);
}
}
}
db.CreateUpdateRightsTrigger(updateRightsTriggerName, tblName, tblList, new List<string>() { Construct.ForeignKeyColumnName(rel.A), Construct.ForeignKeyColumnName(rel.B) });
}
示例6: 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));
}
}
}
}
示例7: 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));
}
}
示例8: 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);
}
示例9: 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);
}
示例10: DoDelete_N_M_Relation
public void DoDelete_N_M_Relation(Relation rel)
{
string assocName = rel.GetAssociationName();
Log.InfoFormat("Deleting N:M Relation: {0}", assocName);
var tblName = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
if (db.CheckFKConstraintExists(tblName, rel.GetRelationAssociationName(RelationEndRole.A)))
db.DropFKConstraint(tblName, rel.GetRelationAssociationName(RelationEndRole.A));
if (db.CheckFKConstraintExists(tblName, rel.GetRelationAssociationName(RelationEndRole.B)))
db.DropFKConstraint(tblName, rel.GetRelationAssociationName(RelationEndRole.B));
if (db.CheckTableExists(tblName))
db.DropTable(tblName);
}
示例11: 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);
}
示例12: TryInspect_N_M_Relation
private bool TryInspect_N_M_Relation(Relation rel, out string assocName, out TableRef tblName, out string fkAName, out string fkBName, out ObjectClass aType, out ObjectClass bType)
{
assocName = rel.GetAssociationName();
tblName = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
fkAName = Construct.ForeignKeyColumnName(rel.A);
fkBName = Construct.ForeignKeyColumnName(rel.B);
aType = rel.A.Type;
bType = rel.B.Type;
return true;
}
示例13: DoChangeRelationName
public void DoChangeRelationName(Relation rel)
{
var savedRel = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
if (!PreMigration(RelationMigrationEventType.Rename, savedRel, rel))
return;
Log.InfoFormat("Changing relation name and all dependencies from {0} to {1}", savedRel.GetAssociationName(), rel.GetAssociationName());
var fkAName = Construct.ForeignKeyColumnName(rel.A);
var fkBName = Construct.ForeignKeyColumnName(rel.B);
var old_fkAName = Construct.ForeignKeyColumnName(savedRel.A);
var old_fkBName = Construct.ForeignKeyColumnName(savedRel.B);
var aType = rel.A.Type;
var bType = rel.B.Type;
var old_aType = savedRel.A.Type;
var old_bType = savedRel.B.Type;
if (rel.GetRelationType() == RelationType.n_m)
{
var srcRelTbl = db.GetTableName(savedRel.Module.SchemaName, savedRel.GetRelationTableName());
var destRelTbl = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
db.RenameFKConstraint(srcRelTbl, savedRel.GetRelationAssociationName(RelationEndRole.A),
aType.GetTableRef(db), old_fkAName, rel.GetRelationAssociationName(RelationEndRole.A), false);
db.RenameFKConstraint(srcRelTbl, savedRel.GetRelationAssociationName(RelationEndRole.B),
bType.GetTableRef(db), old_fkBName, rel.GetRelationAssociationName(RelationEndRole.B), false);
db.RenameTable(srcRelTbl, destRelTbl);
db.RenameColumn(destRelTbl, old_fkAName, fkAName);
db.RenameColumn(destRelTbl, old_fkBName, fkBName);
db.RenameIndex(srcRelTbl, Construct.IndexName(srcRelTbl.Name, old_fkAName), Construct.IndexName(destRelTbl.Name, fkAName));
db.RenameIndex(srcRelTbl, Construct.IndexName(srcRelTbl.Name, old_fkBName), Construct.IndexName(destRelTbl.Name, fkBName));
}
else if (rel.GetRelationType() == RelationType.one_n)
{
if (savedRel.HasStorage(RelationEndRole.A))
{
var tbl = aType.GetTableRef(db);
var refTbl = bType.GetTableRef(db);
var old_tbl = old_aType.GetTableRef(db);
db.RenameFKConstraint(tbl, savedRel.GetAssociationName(), refTbl, old_fkBName, rel.GetAssociationName(), false);
db.RenameColumn(tbl, old_fkBName, fkBName);
db.RenameIndex(tbl, Construct.IndexName(old_tbl.Name, old_fkBName), Construct.IndexName(tbl.Name, fkBName));
}
else if (savedRel.HasStorage(RelationEndRole.B))
{
var tbl = bType.GetTableRef(db);
var refTbl = aType.GetTableRef(db);
var old_tbl = old_bType.GetTableRef(db);
db.RenameFKConstraint(tbl, savedRel.GetAssociationName(), refTbl, old_fkAName, rel.GetAssociationName(), false);
db.RenameColumn(tbl, old_fkAName, fkAName);
db.RenameIndex(tbl, Construct.IndexName(old_tbl.Name, old_fkAName), Construct.IndexName(tbl.Name, fkAName));
}
}
else if (rel.GetRelationType() == RelationType.one_one)
{
if (savedRel.HasStorage(RelationEndRole.A))
{
var tbl = aType.GetTableRef(db);
var refTbl = bType.GetTableRef(db);
var old_tbl = old_aType.GetTableRef(db);
db.RenameFKConstraint(tbl, savedRel.GetRelationAssociationName(RelationEndRole.A), refTbl, old_fkAName, rel.GetRelationAssociationName(RelationEndRole.A), false);
db.RenameColumn(tbl, old_fkBName, fkBName);
db.RenameIndex(tbl, Construct.IndexName(old_tbl.Name, old_fkBName), Construct.IndexName(tbl.Name, fkBName));
}
if (savedRel.HasStorage(RelationEndRole.B))
{
var tbl = bType.GetTableRef(db);
var refTbl = aType.GetTableRef(db);
var old_tbl = old_bType.GetTableRef(db);
db.RenameFKConstraint(tbl, savedRel.GetRelationAssociationName(RelationEndRole.B), refTbl, old_fkBName, rel.GetRelationAssociationName(RelationEndRole.B), false);
db.RenameColumn(tbl, old_fkAName, fkAName);
db.RenameIndex(tbl, Construct.IndexName(old_tbl.Name, old_fkAName), Construct.IndexName(tbl.Name, fkAName));
}
}
PostMigration(RelationMigrationEventType.Rename, savedRel, rel);
}
示例14: Do_N_M_RelationChange_FromNotIndexed_To_Indexed
public void Do_N_M_RelationChange_FromNotIndexed_To_Indexed(Relation rel, RelationEndRole role)
{
var savedRel = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
if (!PreMigration(RelationMigrationEventType.ChangeHasPositionStorage, savedRel, rel))
return;
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 = Construct.ForeignKeyColumnName(rel.GetEndFromRole(role));
db.CreateColumn(tblName, fkName + Zetbox.API.Helper.PositionSuffix, System.Data.DbType.Int32, 0, 0, true);
PostMigration(RelationMigrationEventType.ChangeHasPositionStorage, savedRel, rel);
}
示例15: DoDelete_N_M_Relation
public void DoDelete_N_M_Relation(Relation savedRel)
{
if (!PreMigration(RelationMigrationEventType.Delete, savedRel, null))
return;
string assocName = savedRel.GetAssociationName();
Log.InfoFormat("Deleting N:M Relation: {0}", assocName);
var tblName = db.GetTableName(savedRel.Module.SchemaName, savedRel.GetRelationTableName());
if (db.CheckFKConstraintExists(tblName, savedRel.GetRelationAssociationName(RelationEndRole.A)))
db.DropFKConstraint(tblName, savedRel.GetRelationAssociationName(RelationEndRole.A));
if (db.CheckFKConstraintExists(tblName, savedRel.GetRelationAssociationName(RelationEndRole.B)))
db.DropFKConstraint(tblName, savedRel.GetRelationAssociationName(RelationEndRole.B));
if (db.CheckTableExists(tblName))
db.DropTable(tblName);
PostMigration(RelationMigrationEventType.Delete, savedRel, null);
}