Skip to content

DataSetGraph

Bruce Markham edited this page Nov 29, 2021 · 5 revisions

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 FastGraph.Data module.

Creating a DataSetGraph

You can create a DataSetGraph from any DataSet by using the ToGraph extension method.

using FastGraph.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

FastGraph 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:

graphviz

Clone this wiki locally