C# (CSharp) nHydrate.Generator.Models Table.GetTableHierarchy - 10개의 예제가 발견되었습니다. 이것들은 오픈소스 프로젝트에서 추출된 C# (CSharp)의 nHydrate.Generator.Models.Table.GetTableHierarchy에 대한 실세계 최고 등급의 예제들입니다. 예제들을 평가하여 예제의 품질 향상에 도움을 줄 수 있습니다.
private void ReloadControl()
{
if (ControllerListView != null)
{
ControllerListView.BeginUpdate();
}
try
{
var referenceCollection = (ReferenceCollection)this.Object;
Table parentTable = null;
if (referenceCollection.Parent is Table)
{
parentTable = (Table)referenceCollection.Parent;
}
//Load the list
var shallowColumnNames = new List <string>();
ControllerListView.Items.Clear();
foreach (Reference reference in referenceCollection)
{
var column = ((Column)reference.Object);
shallowColumnNames.Add(column.Name.ToLower());
this.AddColumnNode(reference, column);
}
//Load the inherited columns
if (parentTable != null)
{
var allTables = new List <Table>(parentTable.GetTableHierarchy());
allTables.Remove(parentTable);
//Loop through all base tables and list columns that are NOT included in this table (the PK/audit columns)
foreach (var table in allTables)
{
foreach (var column in table.GeneratedColumns)
{
if (!shallowColumnNames.Contains(column.Name.ToLower()))
{
shallowColumnNames.Add(column.Name.ToLower()); //just in case, no duplicates
this.AddColumnNode(column);
}
}
}
}
}
catch (Exception ex)
{
throw;
}
finally
{
if (ControllerListView != null)
{
ControllerListView.EndUpdate();
}
}
}
/// <summary>
/// Find all relationships that have a specific child table
/// </summary>
/// <param name="table">The table from which all relations begin</param>
/// <param name="includeHierarchy">Determines if the return includes all tables in the inheritence tree</param>
/// <returns></returns>
public ReadOnlyCollection <Relation> FindByChildTable(Table table, bool includeHierarchy)
{
try
{
var retval = new List <Relation>();
var tableList = new List <Table>();
var columnList = new List <Column>();
if (includeHierarchy)
{
tableList.AddRange(table.GetTableHierarchy());
foreach (var t in tableList)
{
foreach (var column in (from x in t.GetColumnsFullHierarchy(true) select x))
{
columnList.Add(column);
}
}
}
else
{
tableList = new List <Table>();
tableList.Add(table);
columnList.AddRange(table.GetColumns());
}
foreach (Relation relation in this)
{
var childTable = (Table)relation.ChildTableRef.Object;
foreach (ColumnRelationship columnRelationship in relation.ColumnRelationships)
{
foreach (var column in columnList)
{
if (tableList.Contains(childTable))
{
if (!retval.Contains(relation))
{
retval.Add(relation);
}
}
}
}
}
return(retval.AsReadOnly());
}
catch (Exception ex)
{
throw;
}
}
/// <summary>
/// Find all relationships that have a specific parent table
/// </summary>
/// <param name="table">The table from which all relations begin</param>
/// <param name="includeHierarchy">Determines if the return includes all tables in the inheritence tree</param>
/// <returns></returns>
public ReadOnlyCollection <ViewRelation> FindByParentTable(Table table, bool includeHierarchy)
{
var tableList = new List <Table>();
var columnList = new List <Column>();
if (includeHierarchy)
{
tableList.AddRange(new List <Table>(table.GetTableHierarchy()));
foreach (var t in tableList)
{
foreach (var column in (from x in t.GetColumnsFullHierarchy(true) select x))
{
columnList.Add(column);
}
}
}
else
{
tableList = new List <Table>();
tableList.Add(table);
columnList.AddRange(table.GetColumns());
}
var retval = new List <ViewRelation>();
foreach (ViewRelation relation in this)
{
var parentTable = (Table)relation.ParentTableRef.Object;
foreach (ViewColumnRelationship columnRelationship in relation.ColumnRelationships)
{
foreach (var column in columnList)
{
if (tableList.Contains(parentTable))
{
if (!retval.Contains(relation))
{
retval.Add(relation);
}
}
}
}
}
return(retval.AsReadOnly());
}
/// <summary>
/// Determines if this table shares a common ancestor with the specified table
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public bool ShareAncestor(Table table)
{
if (table == null) return false;
if (table == this) return false;
var list1 = this.GetTableHierarchy();
var list2 = table.GetTableHierarchy();
return (list1.Intersect(list2).Count() > 0);
}
/// <summary>
/// Determines if the specified table can be a parent of this table
/// </summary>
/// <param name="parentTable"></param>
/// <returns></returns>
public virtual bool CanInherit(Table parentTable)
{
//Ensure that there are no circles
var tList = parentTable.GetTableHierarchy();
return !tList.Contains(this);
}