本文整理汇总了C#中Relation.HasStorage方法的典型用法代码示例。如果您正苦于以下问题:C# Relation.HasStorage方法的具体用法?C# Relation.HasStorage怎么用?C# Relation.HasStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relation
的用法示例。
在下文中一共展示了Relation.HasStorage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRelation
private void ProcessRelation(Relation rel)
{
if (rel.A.Type == rel.B.Type)
{
if (rel.A.Type != cls)
{
throw new ArgumentException(String.Format("contains self-Relation {0} which doesn't match the specified ObjectClass {1}", rel, cls), "rel");
}
if (rel.HasStorage(RelationEndRole.A))
{
ProcessRelationEnd(rel, rel.A);
}
if (rel.HasStorage(RelationEndRole.B))
{
ProcessRelationEnd(rel, rel.B);
}
}
else if (rel.A.Type == cls)
{
if (!rel.HasStorage(RelationEndRole.A))
{
throw new ArgumentException(String.Format("contains Relation {0} which doesn't need storage on the A-side", rel, cls), "rel");
}
ProcessRelationEnd(rel, rel.A);
}
else if (rel.B.Type == cls)
{
if (!rel.HasStorage(RelationEndRole.B))
{
throw new ArgumentException(String.Format("contains Relation {0} which doesn't need storage on the B-side", rel, cls), "rel");
}
ProcessRelationEnd(rel, rel.B);
}
else
{
throw new ArgumentException(String.Format("contains Relation {0} which doesn't match the specified ObjectClass {1}", rel, cls), "rel");
}
}
示例2: 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);
}
}
}
}
示例3: 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);
}
示例4: DoChange_1_1_Storage
public void DoChange_1_1_Storage(Relation rel)
{
Log.InfoFormat("Changing 1:1 Relation Storage: {0}", rel.GetAssociationName());
var saved = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
if (saved.Storage == StorageType.Replicate)
{
// To MergeIntoA or MergeIntoB
if (rel.HasStorage(RelationEndRole.B))
{
Delete_1_1_Relation_DropColumns(saved, saved.A, saved.B, RelationEndRole.A);
}
else if (rel.HasStorage(RelationEndRole.A))
{
Delete_1_1_Relation_DropColumns(saved, saved.B, saved.A, RelationEndRole.B);
}
}
else
{
RelationEnd relEnd;
RelationEnd otherEnd;
RelationEndRole role;
RelationEndRole otherRole;
if (saved.Storage == StorageType.MergeIntoA)
{
// To MergeIntoB or Replicate
relEnd = rel.B;
otherEnd = rel.A;
role = RelationEndRole.B;
otherRole = RelationEndRole.A;
}
else if (saved.Storage == StorageType.MergeIntoB)
{
// To MergeIntoA or Replicate
relEnd = rel.A;
otherEnd = rel.B;
role = RelationEndRole.A;
otherRole = RelationEndRole.B;
}
else
{
throw new InvalidOperationException("Unexpected saved stroage type " + saved.Storage.ToString());
}
New_1_1_Relation_CreateColumns(rel, relEnd, otherEnd, role);
var srcTbl = db.GetTableName(otherEnd.Type.Module.SchemaName, otherEnd.Type.TableName);
var srcCol = Construct.ForeignKeyColumnName(relEnd);
var destTbl = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
var destCol = Construct.ForeignKeyColumnName(otherEnd);
db.MigrateFKs(srcTbl, srcCol, destTbl, destCol);
if (!relEnd.IsNullable())
{
if (!db.CheckColumnContainsNulls(destTbl, destCol))
{
db.AlterColumn(destTbl, destCol, System.Data.DbType.Int32, 0, 0, false, null);
}
else
{
Log.ErrorFormat("Unable to alter NOT NULL column, since table contains data. Leaving nullable column instead");
}
}
if (rel.Storage != StorageType.Replicate)
{
Delete_1_1_Relation_DropColumns(rel, otherEnd, relEnd, otherRole);
}
}
}
示例5: Do_1_N_RelationChange_FromIndexed_To_NotIndexed
public void Do_1_N_RelationChange_FromIndexed_To_NotIndexed(Relation rel)
{
string assocName = rel.GetAssociationName();
Log.InfoFormat("Drop 1:N Relation Position Storage: {0}", assocName);
TableRef tblName;
RelationEnd otherEnd;
if (rel.HasStorage(RelationEndRole.A))
{
tblName = db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName);
otherEnd = rel.B;
}
else if (rel.HasStorage(RelationEndRole.B))
{
tblName = db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName);
otherEnd = rel.A;
}
else
{
Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", assocName, rel.Storage);
return;
}
if (db.CheckColumnExists(tblName, Construct.ListPositionColumnName(otherEnd)))
db.DropColumn(tblName, Construct.ListPositionColumnName(otherEnd));
}
示例6: 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))
//.........这里部分代码省略.........
示例7: 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);
}
}
示例8: 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));
}
示例9: ApplyRememberToDeleteTemplate
private void ApplyRememberToDeleteTemplate(Relation rel, RelationEnd relEnd)
{
var prop = relEnd.Navigator;
var propName = prop != null ? prop.Name : string.Empty;
if (rel.GetOtherEnd(relEnd).Multiplicity == Multiplicity.ZeroOrMore)
{
if (prop != null)
{
this.WriteObjects(" // ", rel.GetAssociationName(), " ZeroOrMore\r\n");
this.WriteObjects(" foreach(NHibernatePersistenceObject x in ", propName, ") {\r\n");
this.WriteObjects(" x.ParentsToDelete.Add(this);\r\n");
this.WriteObjects(" ChildrenToDelete.Add(x);\r\n");
this.WriteObjects(" }\r\n");
}
else
{
this.WriteObjects(" // should fetch && remember parent for ", relEnd.Parent.GetRelationClassName(), "\r\n");
}
}
else
{
if (prop != null && rel.HasStorage(relEnd.GetRole()))
{
this.WriteObjects(" // ", rel.GetAssociationName(), "\r\n");
this.WriteObjects(" if (", propName, " != null) {\r\n");
this.WriteObjects(" ((NHibernatePersistenceObject)", propName, ").ChildrenToDelete.Add(this);\r\n");
this.WriteObjects(" ParentsToDelete.Add((NHibernatePersistenceObject)", propName, ");\r\n");
this.WriteObjects(" }\r\n");
}
else if (prop != null && !rel.HasStorage(relEnd.GetRole()))
{
this.WriteObjects(" // ", rel.GetAssociationName(), "\r\n");
this.WriteObjects(" if (", propName, " != null) {\r\n");
this.WriteObjects(" ((NHibernatePersistenceObject)", propName, ").ParentsToDelete.Add(this);\r\n");
this.WriteObjects(" ChildrenToDelete.Add((NHibernatePersistenceObject)", propName, ");\r\n");
this.WriteObjects(" }\r\n");
}
else
{
this.WriteObjects(" // should fetch && remember children for ", relEnd.Parent.GetRelationClassName(), "\r\n");
}
}
}
示例10: Do_1_N_RelationChange_FromIndexed_To_NotIndexed
public void Do_1_N_RelationChange_FromIndexed_To_NotIndexed(Relation rel)
{
var savedRel = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
if (!PreMigration(RelationMigrationEventType.ChangeHasPositionStorage, savedRel, rel))
return;
string assocName = rel.GetAssociationName();
Log.InfoFormat("Drop 1:N Relation Position Storage: {0}", assocName);
TableRef tblName;
RelationEnd otherEnd;
if (rel.HasStorage(RelationEndRole.A))
{
tblName = rel.A.Type.GetTableRef(db);
otherEnd = rel.B;
}
else if (rel.HasStorage(RelationEndRole.B))
{
tblName = rel.B.Type.GetTableRef(db);
otherEnd = rel.A;
}
else
{
Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", assocName, rel.Storage);
return;
}
if (db.CheckColumnExists(tblName, Construct.ListPositionColumnName(otherEnd)))
db.DropColumn(tblName, Construct.ListPositionColumnName(otherEnd));
PostMigration(RelationMigrationEventType.ChangeHasPositionStorage, savedRel, rel);
}
示例11: DoDelete_1_N_Relation
public void DoDelete_1_N_Relation(Relation savedRel)
{
if (!PreMigration(RelationMigrationEventType.Delete, savedRel, null))
return;
string assocName = savedRel.GetAssociationName();
Log.InfoFormat("Deleting 1:N Relation: {0}", assocName);
TableRef tblName;
bool isIndexed = false;
RelationEnd otherEnd;
if (savedRel.HasStorage(RelationEndRole.A))
{
tblName = savedRel.A.Type.GetTableRef(db);
isIndexed = savedRel.NeedsPositionStorage(RelationEndRole.A);
otherEnd = savedRel.B;
}
else if (savedRel.HasStorage(RelationEndRole.B))
{
tblName = savedRel.B.Type.GetTableRef(db);
isIndexed = savedRel.NeedsPositionStorage(RelationEndRole.B);
otherEnd = savedRel.A;
}
else
{
Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", assocName, savedRel.Storage);
return;
}
var colName = Construct.ForeignKeyColumnName(otherEnd);
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 (isIndexed && db.CheckColumnExists(tblName, Construct.ListPositionColumnName(otherEnd)))
db.DropColumn(tblName, Construct.ListPositionColumnName(otherEnd));
PostMigration(RelationMigrationEventType.Delete, savedRel, null);
}
示例12: DoDelete_1_1_Relation
public void DoDelete_1_1_Relation(Relation savedRel)
{
if (!PreMigration(RelationMigrationEventType.Delete, savedRel, null))
return;
Log.InfoFormat("Deleting 1:1 Relation: {0}", savedRel.GetAssociationName());
if (savedRel.HasStorage(RelationEndRole.A))
{
Delete_1_1_Relation_DropColumns(savedRel, savedRel.A, savedRel.B, RelationEndRole.A);
}
// Difference to 1:N. 1:1 may have storage 'Replicate'
if (savedRel.HasStorage(RelationEndRole.B))
{
Delete_1_1_Relation_DropColumns(savedRel, savedRel.B, savedRel.A, RelationEndRole.B);
}
PostMigration(RelationMigrationEventType.Delete, savedRel, null);
}
示例13: 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);
}
}
}
}