public static DbDataGraph GetDbModelGraph(string connString) { using (var dbInfo = new DbInfo(connString)) //using (var dbInfo = new DbInfoSimple(connString)) { return(GetDbModelGraph(dbInfo)); } }
private static DbDataGraph GetDbModelGraph(DbInfo dbInfo) { var dbGraph = new DbDataGraph(); // add vertexes (tables) var tables = dbInfo.ListSchemaTableNames(); dbGraph.AddVertexRange(tables.Select(t => new DbDataVertex(tableOwner: t.Item1, tableName: t.Item2))); // add edges (FKs) var vertices = dbGraph.Vertices.ToDictionary(v => $"({v.TableOwner}, {v.TableName})", v => v); foreach (var vertice in dbGraph.Vertices) { var tableFkEdgess = dbInfo.ReadTableFks(vertice.TableOwner, vertice.TableName) .Select(fk => new DbDataEdge(vertices[fk.ToString()], vertice)); dbGraph.AddEdgeRange(tableFkEdgess); } return(dbGraph); }