本文整理汇总了C#中Relation.GetAssociationName方法的典型用法代码示例。如果您正苦于以下问题:C# Relation.GetAssociationName方法的具体用法?C# Relation.GetAssociationName怎么用?C# Relation.GetAssociationName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relation
的用法示例。
在下文中一共展示了Relation.GetAssociationName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyObjectReferenceProperty
protected override void ApplyObjectReferenceProperty(Relation rel, RelationEndRole endRole, string propertyName)
{
// TODO: create/use ObjectReference*IMPLEMENTATION* instead (_fk* can already be made available)
RelationEnd relEnd = rel.GetEndFromRole(endRole);
RelationEnd otherEnd = rel.GetOtherEnd(relEnd);
string moduleNamespace = rel.Module.Namespace;
string implName = propertyName + Zetbox.API.Helper.ImplementationSuffix;
string eventName = "On" + propertyName;
string fkBackingName = "_fk_" + propertyName;
string fkGuidBackingName = "_fk_guid_" + propertyName;
string referencedInterface = relEnd.Type.GetDataTypeString();
string referencedImplementation = referencedInterface
+ Host.Settings["extrasuffix"] + Zetbox.API.Helper.ImplementationSuffix;
string associationName = rel.GetAssociationName() + "_" + endRole.ToString();
string targetRoleName = relEnd.RoleName;
string positionPropertyName = rel.NeedsPositionStorage(endRole)
? propertyName + Zetbox.API.Helper.PositionSuffix
: null;
string inverseNavigatorName = relEnd.Navigator != null
? relEnd.Navigator.Name + Zetbox.API.Helper.ImplementationSuffix
: null;
bool inverseNavigatorIsList = false;
bool notifyInverseCollection = true;
bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading;
bool relDataTypeExportable = rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable();
bool callGetterSetterEvents = false;
Templates.Properties.ObjectReferencePropertyTemplate.Call(Host,
ctx,
MembersToSerialize,
moduleNamespace,
"/* not member of an interface, 'ownInterface' should not be used */",
propertyName,
implName,
eventName,
fkBackingName,
fkGuidBackingName,
referencedInterface,
referencedImplementation,
associationName,
targetRoleName,
positionPropertyName,
inverseNavigatorName,
inverseNavigatorIsList,
notifyInverseCollection,
eagerLoading,
relDataTypeExportable,
callGetterSetterEvents,
false, // ObjRef with relation cannot be calculated
false);
}
示例2: TryInspect_1_N_Relation
/// <summary>
/// Tries to dissect a relation for the 1_N case.
/// </summary>
/// <returns>false if something is wrong with the relation definition. The out parameters are only filled correctly when the function returns true.</returns>
internal bool TryInspect_1_N_Relation(
Relation rel, out string assocName,
out RelationEnd relEnd, out RelationEnd otherEnd,
out TableRef tblName, out TableRef refTblName,
out string colName,
out bool hasPersistentOrder, out string listPosName)
{
assocName = rel.GetAssociationName();
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("Skipping Relation '{0}': unsupported Storage set: {1}", assocName, rel.Storage);
otherEnd = null;
relEnd = null;
tblName = null;
refTblName = null;
hasPersistentOrder = default(bool);
colName = null;
listPosName = null;
return false;
}
tblName = relEnd.Type.GetTableRef(db);
refTblName = otherEnd.Type.GetTableRef(db);
hasPersistentOrder = rel.NeedsPositionStorage(relEnd.GetRole());
colName = Construct.ForeignKeyColumnName(otherEnd);
listPosName = Construct.ListPositionColumnName(otherEnd);
return true;
}
示例3: Call
public static void Call(Arebis.CodeGeneration.IGenerationHost host,
IZetboxContext ctx,
Serialization.SerializationMembersList serializationList,
string ownInterface,
string name,
string referencedInterface,
Relation rel,
RelationEndRole endRole,
bool callGetterSetterEvents,
bool updateInverseNavigator,
string assocNameSuffix)
{
// TODO: split off relation expansion in own Call() method
RelationEnd relEnd = rel.GetEndFromRole(endRole);
RelationEnd otherEnd = rel.GetOtherEnd(relEnd);
string moduleNamespace = rel.Module.Namespace;
string implName = name + Zetbox.API.Helper.ImplementationSuffix;
string eventName = "On" + name;
string fkBackingName = "_fk_" + name;
string fkGuidBackingName = "_fk_guid_" + name;
string referencedImplementation = referencedInterface
+ host.Settings["extrasuffix"] + Zetbox.API.Helper.ImplementationSuffix;
string associationName = rel.GetAssociationName() + assocNameSuffix;
string targetRoleName = otherEnd.RoleName;
string positionPropertyName = rel.NeedsPositionStorage(endRole)
? Construct.ListPositionPropertyName(relEnd)
: null;
string inverseNavigatorName = updateInverseNavigator && otherEnd.Navigator != null
? otherEnd.Navigator.Name
: null;
bool inverseNavigatorIsList = otherEnd.Navigator != null && otherEnd.Navigator.GetIsList();
bool eagerLoading = relEnd.Navigator != null && relEnd.Navigator.EagerLoading;
bool relDataTypeExportable = rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable();
Call(host,
ctx,
serializationList,
moduleNamespace,
ownInterface,
name,
implName,
eventName,
fkBackingName,
fkGuidBackingName,
referencedInterface,
referencedImplementation,
associationName,
targetRoleName,
positionPropertyName,
inverseNavigatorName,
inverseNavigatorIsList,
eagerLoading,
relDataTypeExportable,
callGetterSetterEvents,
false, // ObjRef with relation cannot be calculated
false);
}
示例4: 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());
}
}
示例5: DoChangeRelationType_from_n_m_to_1_n
public void DoChangeRelationType_from_n_m_to_1_n(Relation rel)
{
string destAssocName = rel.GetAssociationName();
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", destAssocName, rel.Storage);
return;
}
var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
var srcTbl = db.GetTableName(saved.Module.SchemaName, saved.GetRelationTableName());
var srcCol = saved.GetRelationFkColumnName(otherEnd.GetRole());
var srcFKCol = saved.GetRelationFkColumnName(relEnd.GetRole());
if (!db.CheckFKColumnContainsUniqueValues(srcTbl, srcCol))
{
Log.ErrorFormat("Unable to change Relation '{0}' from n:m to 1:n. Data is not unique", destAssocName);
return;
}
var destTblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
var destColName = Construct.ForeignKeyColumnName(otherEnd);
DoNew_1_N_Relation(rel);
db.CopyFKs(srcTbl, srcCol, destTblName, destColName, srcFKCol);
DoDelete_N_M_Relation(saved);
}
示例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_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);
}
示例8: DoNew_1_1_Relation
public void DoNew_1_1_Relation(Relation rel)
{
Log.InfoFormat("New 1:1 Relation: {0}", rel.GetAssociationName());
if (rel.Storage == StorageType.MergeIntoA || rel.Storage == StorageType.Replicate)
{
New_1_1_Relation_CreateColumns(rel, rel.A, rel.B, RelationEndRole.A);
}
if (rel.Storage == StorageType.MergeIntoB || rel.Storage == StorageType.Replicate)
{
New_1_1_Relation_CreateColumns(rel, rel.B, rel.A, RelationEndRole.B);
}
}
示例9: DoNew_1_N_Relation
public void DoNew_1_N_Relation(Relation rel)
{
string assocName = rel.GetAssociationName();
Log.InfoFormat("New 1:N Relation: {0}", assocName);
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 = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
var refTblName = db.GetTableName(otherEnd.Type.Module.SchemaName, otherEnd.Type.TableName);
bool isIndexed = rel.NeedsPositionStorage(relEnd.GetRole());
var colName = Construct.ForeignKeyColumnName(otherEnd);
var indexName = Construct.ListPositionColumnName(otherEnd);
CreateFKColumn(otherEnd, tblName, colName);
db.CreateFKConstraint(tblName, refTblName, colName, assocName, false);
db.CreateIndex(tblName, Construct.IndexName(tblName.Name, colName), false, false, colName);
if (isIndexed)
{
Log.InfoFormat("Creating position column '{0}.{1}'", tblName, indexName);
db.CreateColumn(tblName, indexName, System.Data.DbType.Int32, 0, 0, true);
}
}
示例10: DoDelete_1_N_Relation
public void DoDelete_1_N_Relation(Relation rel)
{
string assocName = rel.GetAssociationName();
Log.InfoFormat("Deleting 1:N Relation: {0}", assocName);
TableRef tblName;
bool isIndexed = false;
RelationEnd otherEnd;
if (rel.HasStorage(RelationEndRole.A))
{
tblName = db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName);
isIndexed = rel.NeedsPositionStorage(RelationEndRole.A);
otherEnd = rel.B;
}
else if (rel.HasStorage(RelationEndRole.B))
{
tblName = db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName);
isIndexed = rel.NeedsPositionStorage(RelationEndRole.B);
otherEnd = rel.A;
}
else
{
Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", assocName, rel.Storage);
return;
}
if (db.CheckFKConstraintExists(tblName, assocName))
db.DropFKConstraint(tblName, assocName);
string colName = Construct.ForeignKeyColumnName(otherEnd);
if (db.CheckColumnExists(tblName, colName))
db.DropColumn(tblName, colName);
if (isIndexed && db.CheckColumnExists(tblName, Construct.ListPositionColumnName(otherEnd)))
db.DropColumn(tblName, Construct.ListPositionColumnName(otherEnd));
}
示例11: 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);
}
示例12: DoDelete_1_1_Relation
public void DoDelete_1_1_Relation(Relation rel)
{
Log.InfoFormat("Deleting 1:1 Relation: {0}", rel.GetAssociationName());
if (rel.HasStorage(RelationEndRole.A))
{
Delete_1_1_Relation_DropColumns(rel, rel.A, rel.B, RelationEndRole.A);
}
// Difference to 1:N. 1:1 may have storage 'Replicate'
if (rel.HasStorage(RelationEndRole.B))
{
Delete_1_1_Relation_DropColumns(rel, rel.B, rel.A, RelationEndRole.B);
}
}
示例13: ObjectIsValid
public static void ObjectIsValid(Relation obj, ObjectIsValidEventArgs e)
{
if (obj.A != null && obj.B != null && obj.GetAssociationName().Length > 60)
{
e.Errors.Add(string.Format("The relation name '{0}' (FK_<a>_<verb>_<b>) exceed 60 chars. This could violate a database (Postgres) max identifier length.", obj.GetAssociationName()));
}
}
示例14: 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;
}
示例15: 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);
}