public void AddTable(DbTable t) { int ct = 0; foreach (DbTableConstraint constraint in t.references.Each()) { if ((showExplicit.Checked && constraint.isForeignKey) || (showInferred.Checked && constraint.isSloppyForeignKey)) { ct++; } } foreach (DbTableConstraint constraint in t.constraints.Values) { if ((showExplicit.Checked && constraint.isForeignKey) || (showInferred.Checked && constraint.isSloppyForeignKey)) { ct++; } } if (ct == 0) { return; } string leftTable = T.AppendTo(t.name, t.GetAlias(true), " "); Microsoft.Msagl.Drawing.Shape shape = Microsoft.Msagl.Drawing.Shape.Box; Color backColor = Color.DarkKhaki; Color borderColor = backColor; int radius = 20; DrawingNode node = drawingGraph.AddNode(leftTable); node.Attr.FillColor = node.Attr.FillColor = GraphColor(backColor); node.Attr.Color = GraphColor(borderColor); node.Attr.LabelMargin = 10; node.Attr.Shape = shape; node.Attr.XRadius = radius; node.Attr.YRadius = radius; node.LabelText = leftTable; foreach (DbTableConstraint constraint in t.constraints.Values) { if ((showExplicit.Checked && constraint.isForeignKey) || (showInferred.Checked && constraint.isSloppyForeignKey)) { string rightTable = T.AppendTo(constraint.referencedTable.name, constraint.referencedTable.GetAlias(true), " "); string edgeInfo = constraint.RenderJoinCols(true); Microsoft.Msagl.Drawing.Edge e = drawingGraph.AddEdge(leftTable, edgeInfo, rightTable); e.Attr.Weight = 6; paths.Add(t.name + "." + constraint.referencedTable.name); } } }
public string AddTable(DbTable t, bool includeAlias) { string alias = ""; if (includeAlias) { alias = t.GetAlias(true); } int insertPos = 0; if (query.from == null) { Keyword k = Keyword.CreateKeyword(0, "from"); k.parentQuery = query; insertPos = k.GetInsertOffset(); inserts.Add(insertPos, ("from " + t.name + " " + alias).Trim()); } else { if (query.from.tables.GetTableByName(t.name) == null) { insertPos = query.from.rightExtent; while (Char.IsWhiteSpace(Query.rootQuery.expression[insertPos - 1])) { insertPos--; } string bestJoin = null; foreach (Table table in query.from.tables.tokens) { string join = table.dbTable.RenderJoin(t.name, includeAlias); if (join != "" && (bestJoin == null || bestJoin.CountOccurrances('.') > join.CountOccurrances('.'))) { bestJoin = join; } } if (bestJoin != null) { inserts.Add(insertPos, bestJoin); } } } return(alias); }