DataSetGraph - KeRNeLith/QuikGraph GitHub Wiki
DataSetGraph
The DataSetGraph
is a directed graph of created from a DataSet
schema, where each table is a vertex and each table relation is an edge.
It is defined in the QuikGraph.Data module.
DataSetGraph
Creating a You can create a DataSetGraph
from any DataSet
by using the ToGraph
extension method.
using QuikGraph.Data;
DataSet dataSet = ...;
DataSetGraph graph = dataSet.ToGraph();
Topological Sort
A very useful application of the DataSetGraph
is to compute the topological sort of the tables. The topological sort gives you the order in which you should fill tables (or reversely delete them).
DataSet dataSet = new (); // Get your data set
DataSetGraph graph = dataSet.ToGraph(); // Wraps the dataset into a DataSetGraph
foreach(DataTable table in graph.TopologicalSort()) // Applies a topological sort to the data set graph
{
// ...
}
Graphviz
QuikGraph has a bridge to Graphviz that has a specialized version for DataSetGraph
available through DataSetGraphvizAlgorithm
or more easily with extension ToGraphviz
.
DataSet dataSet = new ();
DataSetGraph graph = dataSet.ToGraph();
string dot = graph.ToGraphviz();
Which can produce results like this: