private void FindPaths() { Paths.Clear(); // Scan measures to find fact tables List <Table> facts = new List <Table>(); foreach (IDataElement elem in this) { if (elem is MeasureDef) { facts.Add(((MeasureDef)elem).Source.Table); } } if (facts.Count > 0) { // Uses fact tables as root nodes TableTree tree = new TableTree(); foreach (Table fact in facts) { TableTreeNode n = new TableTreeNode(fact); tree.Nodes.Add(n); Walkthrough(n); } // Scan attributes to find dimension tables List <Table> dimTables = new List <Table>(); foreach (IDataElement elem in this) { if (elem is AttributeDef) { AttributeDef attr = (AttributeDef)elem; if (!dimTables.Contains(attr.KeyColumns[0].Table)) { dimTables.Add(attr.KeyColumns[0].Table); } } } foreach (Table table in dimTables) { TableTreeNode n = tree.FindNodeByTable(table); if (n != null) { JoinPath jp = n.GetJoinPath(); if (jp != null) { Paths.Add(jp); } } } } }
private void Walkthrough(TableTreeNode node) { // Uses destination of all the relationsips of current table to build child nodes, // keeps walkthrough till the end of the branch. foreach (Relationship rel in node.Table.Relationships) { TableTreeNode child = new TableTreeNode(rel.Destination); node.Add(child); Walkthrough(child); } }
public JoinPath GetJoinPath() { List <Relationship> list = new List <Relationship>(); TableTreeNode current = this; Table last = null; // Trace back to root node which is a fact table and add all the paths(relationships) to the list while (current != null) { TableTreeNode parent = current.Parent; if (parent != null) { Relationship rel = parent.Table.FindRelationshipByDestination(current.Table); if (rel != null) { list.Add(rel); } last = parent.Table; } current = parent; } return(new JoinPath(last, Table, list)); }
public TableTreeNode Add(TableTreeNode node) { node.Parent = this; Children.Add(node); return(node); }