本文整理汇总了C#中Relation.GetRelationType方法的典型用法代码示例。如果您正苦于以下问题:C# Relation.GetRelationType方法的具体用法?C# Relation.GetRelationType怎么用?C# Relation.GetRelationType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relation
的用法示例。
在下文中一共展示了Relation.GetRelationType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Call
public static void Call(Arebis.CodeGeneration.IGenerationHost host,
IZetboxContext ctx,
Templates.Serialization.SerializationMembersList serializationList,
Relation rel, RelationEndRole endRole, string backingCollectionType)
{
if (host == null) { throw new ArgumentNullException("host"); }
if (rel == null) { throw new ArgumentNullException("rel"); }
RelationEnd relEnd = rel.GetEndFromRole(endRole);
RelationEnd otherEnd = rel.GetOtherEnd(relEnd);
string name = relEnd.Navigator.Name;
string exposedCollectionInterface = rel.NeedsPositionStorage(otherEnd.GetRole()) ? "IList" : "ICollection";
string referencedInterface = otherEnd.Type.GetDataTypeString();
string backingName = "_" + name;
string aSideType = rel.A.Type.GetDataTypeString();
string bSideType = rel.B.Type.GetDataTypeString();
string entryType = rel.GetRelationFullName() + host.Settings["extrasuffix"] + Zetbox.API.Helper.ImplementationSuffix;
string providerCollectionType = (rel.NeedsPositionStorage(otherEnd.GetRole()) ? "IList<" : "ICollection<")
+ entryType + ">";
bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading;
bool serializeRelationEntries = rel.GetRelationType() == RelationType.n_m;
string entryProxyType = entryType + "." + rel.GetRelationClassName() + "Proxy";
string inverseNavigatorName = otherEnd.Navigator != null ? otherEnd.Navigator.Name : null;
Call(host, ctx, serializationList, name, exposedCollectionInterface, referencedInterface, backingName, backingCollectionType, aSideType, bSideType, entryType, providerCollectionType, rel.ExportGuid, endRole, eagerLoading, serializeRelationEntries, entryProxyType, inverseNavigatorName);
}
示例2: 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));
}
}
}
}
示例3: IsChangeRelationType_from_n_m_to_1_n
public bool IsChangeRelationType_from_n_m_to_1_n(Relation rel)
{
var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
if (saved == null) return false;
return
saved.GetRelationType() == RelationType.n_m &&
rel.GetRelationType() == RelationType.one_n;
}
示例4: IsChangeRelationType
public bool IsChangeRelationType(Relation rel)
{
var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
if (saved == null) return false;
return saved.GetRelationType() != rel.GetRelationType();
}
示例5: DoChangeRelationEndTypes
public void DoChangeRelationEndTypes(Relation rel)
{
var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
if (rel.GetRelationType() == RelationType.n_m)
{
var oldTblName = db.GetTableName(saved.Module.SchemaName, saved.GetRelationTableName());
if (db.CheckTableContainsData(oldTblName))
{
if (saved.A.Type.AndParents(cls => cls.BaseObjectClass).Select(cls => cls.ExportGuid).Contains(rel.A.Type.ExportGuid)
&& saved.B.Type.AndParents(cls => cls.BaseObjectClass).Select(cls => cls.ExportGuid).Contains(rel.B.Type.ExportGuid))
{
string assocName = rel.GetAssociationName();
Log.InfoFormat("Rewiring N:M Relation: {0}", assocName);
if (db.CheckFKConstraintExists(oldTblName, saved.GetRelationAssociationName(RelationEndRole.A)))
db.DropFKConstraint(oldTblName, saved.GetRelationAssociationName(RelationEndRole.A));
if (db.CheckFKConstraintExists(oldTblName, saved.GetRelationAssociationName(RelationEndRole.B)))
db.DropFKConstraint(oldTblName, saved.GetRelationAssociationName(RelationEndRole.B));
// renaming is handled by DoChangeRelationName
//db.RenameTable(oldTblName, newTblName);
var fkAName = saved.GetRelationFkColumnName(RelationEndRole.A);
var fkBName = saved.GetRelationFkColumnName(RelationEndRole.B);
db.CreateFKConstraint(oldTblName, db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), fkAName, saved.GetRelationAssociationName(RelationEndRole.A), false);
db.CreateFKConstraint(oldTblName, db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), fkBName, saved.GetRelationAssociationName(RelationEndRole.B), false);
}
else
{
Log.WarnFormat("Unable to drop old relation. Relation has some instances. Table: " + oldTblName);
}
}
else
{
DoDelete_N_M_Relation(saved);
DoNew_N_M_Relation(rel);
}
}
else if (rel.GetRelationType() == RelationType.one_n)
{
RelationEnd relEnd, otherEnd;
switch (rel.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", rel.GetAssociationName(), rel.Storage);
return;
}
var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
var colName = Construct.ForeignKeyColumnName(otherEnd);
if (db.CheckColumnContainsValues(tblName, colName))
{
Log.WarnFormat("Unable to drop old relation. Relation has some instances. Table: " + tblName);
}
else
{
DoDelete_1_N_Relation(saved);
DoNew_1_N_Relation(rel);
}
}
else if (rel.GetRelationType() == RelationType.one_one)
{
RelationEnd relEnd, otherEnd;
switch (rel.Storage)
{
case StorageType.MergeIntoA:
case StorageType.Replicate:
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", rel.GetAssociationName(), rel.Storage);
return;
}
var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
var colName = Construct.ForeignKeyColumnName(otherEnd);
if (db.CheckColumnContainsValues(tblName, colName))
{
Log.WarnFormat("Unable to drop old relation. Relation has some instances. Table: " + tblName);
}
else
{
//.........这里部分代码省略.........
示例6: 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);
}
示例7: DoChangeRelationEndTypes
public void DoChangeRelationEndTypes(Relation rel)
{
var savedRel = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
if (!PreMigration(RelationMigrationEventType.ChangeEndType, savedRel, rel))
return;
string assocName = rel.GetAssociationName();
Log.InfoFormat("Changing relation end types from old rel '{0}' to '{1}'", savedRel.GetAssociationName(), assocName);
var moveUp = savedRel.A.Type.AndParents(cls => cls.BaseObjectClass).Select(cls => cls.ExportGuid).Contains(rel.A.Type.ExportGuid)
&& savedRel.B.Type.AndParents(cls => cls.BaseObjectClass).Select(cls => cls.ExportGuid).Contains(rel.B.Type.ExportGuid);
Log.DebugFormat("moveUp = {0}", moveUp);
if (rel.GetRelationType() == RelationType.n_m)
{
var oldTblName = db.GetTableName(savedRel.Module.SchemaName, savedRel.GetRelationTableName());
var containsData = db.CheckTableContainsData(oldTblName);
if (!containsData || moveUp)
{
Log.DebugFormat("Rewiring N:M Relation: {0}", assocName);
if (db.CheckFKConstraintExists(oldTblName, savedRel.GetRelationAssociationName(RelationEndRole.A)))
db.DropFKConstraint(oldTblName, savedRel.GetRelationAssociationName(RelationEndRole.A));
if (db.CheckFKConstraintExists(oldTblName, savedRel.GetRelationAssociationName(RelationEndRole.B)))
db.DropFKConstraint(oldTblName, savedRel.GetRelationAssociationName(RelationEndRole.B));
// renaming is handled by DoChangeRelationName
//db.RenameTable(oldTblName, newTblName);
var fkAName = Construct.ForeignKeyColumnName(savedRel.A);
var fkBName = Construct.ForeignKeyColumnName(savedRel.B);
db.CreateFKConstraint(oldTblName, rel.A.Type.GetTableRef(db), fkAName, savedRel.GetRelationAssociationName(RelationEndRole.A), false);
db.CreateFKConstraint(oldTblName, rel.B.Type.GetTableRef(db), fkBName, savedRel.GetRelationAssociationName(RelationEndRole.B), false);
}
else
{
Log.WarnFormat("Unable to rewire relation. Relation has some instances. Table: " + oldTblName);
}
}
else if (rel.GetRelationType() == RelationType.one_n)
{
RelationEnd relEnd, otherEnd;
switch (rel.Storage)
{
case StorageType.MergeIntoA:
relEnd = rel.A;
otherEnd = rel.B;
break;
case StorageType.MergeIntoB:
otherEnd = rel.A;
relEnd = rel.B;
break;
default:
Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", assocName, rel.Storage);
return;
}
var tblName = relEnd.Type.GetTableRef(db);
var refTblName = otherEnd.Type.GetTableRef(db);
var colName = Construct.ForeignKeyColumnName(otherEnd);
var containsData = db.CheckColumnContainsValues(tblName, colName);
if (!containsData || moveUp)
{
// was renamed by DoChangeRelationName
Log.DebugFormat("Rewiring 1:n Relation: {0}", assocName);
if (db.CheckFKConstraintExists(tblName, assocName))
db.DropFKConstraint(tblName, assocName);
db.CreateFKConstraint(tblName, refTblName, colName, assocName, false);
}
else
{
Log.WarnFormat("Unable to rewire relation. Relation has some instances. Table: " + tblName);
}
}
else if (rel.GetRelationType() == RelationType.one_one)
{
RelationEnd relEnd, otherEnd;
switch (rel.Storage)
{
case StorageType.MergeIntoA:
case StorageType.Replicate:
relEnd = rel.A;
otherEnd = rel.B;
break;
case StorageType.MergeIntoB:
otherEnd = rel.A;
relEnd = rel.B;
break;
default:
Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", assocName, rel.Storage);
return;
}
//.........这里部分代码省略.........