本文整理汇总了C#中Relation.GetRelationAssociationName方法的典型用法代码示例。如果您正苦于以下问题:C# Relation.GetRelationAssociationName方法的具体用法?C# Relation.GetRelationAssociationName怎么用?C# Relation.GetRelationAssociationName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relation
的用法示例。
在下文中一共展示了Relation.GetRelationAssociationName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
}
示例2: DoChangeRelationType_from_1_n_to_1_1
public void DoChangeRelationType_from_1_n_to_1_1(Relation rel)
{
var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
string srcAssocName = saved.GetAssociationName();
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);
string srcColName = Construct.ForeignKeyColumnName(otherEnd);
bool srcIsIndexed = rel.NeedsPositionStorage(relEnd.GetRole());
string srcIndexName = Construct.ListPositionColumnName(otherEnd);
if (!db.CheckFKColumnContainsUniqueValues(srcTblName, srcColName))
{
Log.ErrorFormat("Unable to change Relation '{0}' from 1:n to 1:1. Data is not unique", srcAssocName);
return;
}
if (db.CheckFKConstraintExists(srcTblName, srcAssocName))
db.DropFKConstraint(srcTblName, srcAssocName);
if (srcIsIndexed && db.CheckColumnExists(srcTblName, srcIndexName))
db.DropColumn(srcTblName, srcIndexName);
if (db.CheckIndexExists(srcTblName, Construct.IndexName(srcTblName.Name, srcColName)))
db.DropIndex(srcTblName, Construct.IndexName(srcTblName.Name, srcColName));
bool aCreated = false;
bool bCreated = false;
// Difference to 1:N. 1:1 may have storage 'Replicate'
// First try to migrate columns
// And only migrate because the source data might be used twice
if (rel.HasStorage(RelationEndRole.A))
{
var destTblName = db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName);
var destColName = Construct.ForeignKeyColumnName(rel.B);
if (destTblName != srcTblName)
{
New_1_1_Relation_CreateColumns(rel, rel.A, rel.B, RelationEndRole.A);
db.MigrateFKs(srcTblName, srcColName, destTblName, destColName);
aCreated = true;
}
}
if (rel.HasStorage(RelationEndRole.B))
{
var destTblName = db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName);
var destColName = Construct.ForeignKeyColumnName(rel.A);
if (destTblName != srcTblName)
{
New_1_1_Relation_CreateColumns(rel, rel.B, rel.A, RelationEndRole.B);
db.MigrateFKs(srcTblName, srcColName, destTblName, destColName);
bCreated = true;
}
}
bool srcColWasReused = false;
// Then try to rename columns
if (rel.HasStorage(RelationEndRole.A) && !aCreated)
{
var destTblName = db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName);
var destColName = Construct.ForeignKeyColumnName(rel.B);
if (destTblName == srcTblName && destColName != srcColName)
{
db.RenameColumn(destTblName, srcColName, destColName);
}
var assocName = rel.GetRelationAssociationName(RelationEndRole.A);
var refTblName = db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName);
db.CreateFKConstraint(destTblName, refTblName, destColName, assocName, false);
db.CreateIndex(destTblName, Construct.IndexName(destTblName.Name, destColName), true, false, destColName);
srcColWasReused = true;
}
if (rel.HasStorage(RelationEndRole.B) && !bCreated)
{
var destTblName = db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName);
var destColName = Construct.ForeignKeyColumnName(rel.A);
if (destTblName == srcTblName && destColName != srcColName)
{
db.RenameColumn(destTblName, srcColName, destColName);
}
var assocName = rel.GetRelationAssociationName(RelationEndRole.B);
var refTblName = db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName);
db.CreateFKConstraint(destTblName, refTblName, destColName, assocName, false);
db.CreateIndex(destTblName, Construct.IndexName(destTblName.Name, destColName), true, false, destColName);
srcColWasReused = true;
}
if (!srcColWasReused && db.CheckColumnExists(srcTblName, srcColName))
//.........这里部分代码省略.........
示例3: Check_1_1_RelationColumns
private void Check_1_1_RelationColumns(Relation rel, RelationEnd relEnd, RelationEndRole role)
{
if (rel.HasStorage(role))
{
var tblName = relEnd.Type.GetTableRef(db);
RelationEnd otherEnd = rel.GetOtherEnd(relEnd);
var refTblName = otherEnd.Type.GetTableRef(db);
string colName = Construct.ForeignKeyColumnName(otherEnd);
string assocName = rel.GetRelationAssociationName(role);
string idxName = Construct.IndexName(tblName.Name, colName);
var realIsNullable = otherEnd.IsNullable();
if (realIsNullable == false)
realIsNullable = relEnd.Type.GetTableMapping() == TableMapping.TPH && relEnd.Type.BaseObjectClass != null;
CheckColumn(tblName, Construct.ForeignKeyColumnName(otherEnd), System.Data.DbType.Int32, 0, 0, realIsNullable, null);
if (!db.CheckFKConstraintExists(tblName, assocName))
{
Log.WarnFormat("FK Constraint '{0}' is missing", assocName);
if (repair)
{
db.CreateFKConstraint(tblName, refTblName, colName, assocName, false);
}
}
if (!db.CheckIndexExists(tblName, idxName))
{
Log.WarnFormat("Index '{0}' is missing", idxName);
if (repair)
{
db.CreateIndex(tblName, idxName, true, false, colName);
}
}
}
}
示例4: New_1_1_Relation_CreateColumns
private void New_1_1_Relation_CreateColumns(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role)
{
var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
var refTblName = db.GetTableName(otherEnd.Type.Module.SchemaName, otherEnd.Type.TableName);
var colName = Construct.ForeignKeyColumnName(otherEnd);
var assocName = rel.GetRelationAssociationName(role);
var idxName = Construct.IndexName(tblName.Name, colName);
CreateFKColumn(otherEnd, tblName, colName);
db.CreateFKConstraint(tblName, refTblName, colName, assocName, false);
if (db.CheckIndexPossible(tblName, idxName, true, false, colName))
db.CreateIndex(tblName, idxName, true, false, colName);
else
Log.WarnFormat("Cannot create index: {0}", idxName);
if (rel.NeedsPositionStorage(role))
{
Log.ErrorFormat("1:1 Relation should never need position storage, but this one does!");
}
}
示例5: 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));
}
}
}
}
示例6: 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);
}
示例7: Delete_1_1_Relation_DropColumns
private void Delete_1_1_Relation_DropColumns(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role)
{
var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
var colName = Construct.ForeignKeyColumnName(otherEnd);
var assocName = rel.GetRelationAssociationName(role);
if (db.CheckFKConstraintExists(tblName, assocName))
db.DropFKConstraint(tblName, assocName);
if (db.CheckColumnExists(tblName, colName))
db.DropColumn(tblName, colName);
if (rel.NeedsPositionStorage(role) && db.CheckColumnExists(tblName, Construct.ListPositionColumnName(otherEnd)))
db.DropColumn(tblName, Construct.ListPositionColumnName(otherEnd));
}
示例8: Delete_1_1_Relation_DropColumns
private void Delete_1_1_Relation_DropColumns(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role)
{
var tblName = relEnd.Type.GetTableRef(db);
var colName = Construct.ForeignKeyColumnName(otherEnd);
var assocName = rel.GetRelationAssociationName(role);
var indexName = Construct.IndexName(tblName.Name, colName);
var checkConstraintName = Construct.CheckConstraintName(tblName.Name, colName);
if (db.CheckFKConstraintExists(tblName, assocName))
db.DropFKConstraint(tblName, assocName);
if (db.CheckIndexExists(tblName, indexName))
db.DropIndex(tblName, indexName);
if (db.CheckCheckConstraintExists(tblName, checkConstraintName))
db.DropCheckConstraint(tblName, checkConstraintName);
if (db.CheckColumnExists(tblName, colName))
db.DropColumn(tblName, colName);
if (rel.NeedsPositionStorage(role) && db.CheckColumnExists(tblName, Construct.ListPositionColumnName(otherEnd)))
db.DropColumn(tblName, Construct.ListPositionColumnName(otherEnd));
}
示例9: 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);
}
示例10: TryInspect_1_1_Relation
internal bool TryInspect_1_1_Relation(Relation rel, RelationEnd relEnd, RelationEnd otherEnd, RelationEndRole role, out TableRef tblName, out TableRef refTblName, out string assocName, out string colName, out string idxName)
{
tblName = relEnd.Type.GetTableRef(db);
refTblName = otherEnd.Type.GetTableRef(db);
assocName = rel.GetRelationAssociationName(role);
colName = Construct.ForeignKeyColumnName(otherEnd);
idxName = Construct.IndexName(tblName.Name, colName);
return true;
}
示例11: 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);
}
示例12: DoNew_N_M_Relation
public void DoNew_N_M_Relation(Relation rel)
{
if (!PreMigration(RelationMigrationEventType.Add, null, rel))
return;
string assocName, fkAName, fkBName;
TableRef tblName;
ObjectClass aType, bType;
if (!TryInspect_N_M_Relation(rel, out assocName, out tblName, out fkAName, out fkBName, out aType, out bType))
{
return;
}
Log.InfoFormat("New N:M Relation: {0}", assocName);
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 (aType.ImplementsIExportable() && bType.ImplementsIExportable())
{
db.CreateColumn(tblName, "ExportGuid", System.Data.DbType.Guid, 0, 0, false, new NewGuidDefaultConstraint());
}
db.CreateFKConstraint(tblName, aType.GetTableRef(db), fkAName, rel.GetRelationAssociationName(RelationEndRole.A), false);
db.CreateIndex(tblName, Construct.IndexName(tblName.Name, fkAName), false, false, fkAName);
db.CreateFKConstraint(tblName, bType.GetTableRef(db), fkBName, rel.GetRelationAssociationName(RelationEndRole.B), false);
db.CreateIndex(tblName, Construct.IndexName(tblName.Name, fkBName), false, false, fkBName);
if (schema.GetQuery<RoleMembership>().Where(rm => rm.Relations.Contains(rel)).Count() > 0)
{
// Relation is in a ACL selector
DoCreateUpdateRightsTrigger(rel);
}
PostMigration(RelationMigrationEventType.Add, null, rel);
}
示例13: 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);
}
示例14: Check_1_1_RelationColumns
private void Check_1_1_RelationColumns(Relation rel, RelationEnd relEnd, RelationEndRole role)
{
if (rel.HasStorage(role))
{
var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
RelationEnd otherEnd = rel.GetOtherEnd(relEnd);
var refTblName = db.GetTableName(otherEnd.Type.Module.SchemaName, otherEnd.Type.TableName);
string colName = Construct.ForeignKeyColumnName(otherEnd);
string assocName = rel.GetRelationAssociationName(role);
string idxName = Construct.IndexName(tblName.Name, colName);
CheckColumn(tblName, Construct.ForeignKeyColumnName(otherEnd), System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null);
if (!db.CheckFKConstraintExists(tblName, assocName))
{
Log.WarnFormat("FK Constraint '{0}' is missing", assocName);
if (repair)
{
db.CreateFKConstraint(tblName, refTblName, colName, assocName, false);
}
}
if (!db.CheckIndexExists(tblName, idxName))
{
Log.WarnFormat("Index '{0}' is missing", idxName);
if (repair)
{
db.CreateIndex(tblName, idxName, true, false, colName);
}
}
}
}