Dependencies as in... relationships or inheritance dependencies? Or both?
It's not that hard. Use algorithmia
(already available to you in a .lpt template) -> Create a new directed graph (DirectedGraph is a type in algorithmia) and add all entities to it. Then traverse the entitymodel graph in the project and for each relationship found, add a directed edge from FK to PK to your new graph, or in case of an m:n relationship, just skip it (as an m:n relationship depends on 2 m:1 relationships, which are already in the list of relationships you're traversing). Then traverse the inheritanceinfo graph and add for each edge found an edge to the new graph from subtype to supertype, if the inheritance hierarchy is of type TPE. Otherwise skip it (as they're mapped onto the same target, as the heirarchy type is TPEH)
The project doesn't expose a method which expose dependencies combined (relationship+inheritance). And you want it combined, as otherwise you have to do it manually anyway.
Then use algorithmia's topological sorting algorithm (2 lines of code) to sort the directed graph topologically. This will give you the dependencies in the right order. The algorithm has parameters which allows you to configure what the order has to be and whether it has to fail when it detects a cycle. See Algorithmia's sourcecode and tests for details on this.
example:
[Test]
public void TopologicalSorterOnDirectedAcyclicGraphWhereDirectionMeansDependency()
{
DirectedGraph<string, DirectedEdge<string>> graph = new DirectedGraph<string, DirectedEdge<string>>();
graph.Add(new DirectedEdge<string>("A", "B")); // A->B
graph.Add(new DirectedEdge<string>("A", "C")); // A->C
graph.Add(new DirectedEdge<string>("B", "D")); // B->D
graph.Add(new DirectedEdge<string>("C", "D")); // C->D
graph.Add(new DirectedEdge<string>("D", "E")); // D->E
graph.Add(new DirectedEdge<string>("H", "G")); // H->G
graph.Add(new DirectedEdge<string>("G", "F")); // G->F
TopologicalSorter<string, DirectedEdge<string>> sorter = new TopologicalSorter<string, DirectedEdge<string>>(graph);
sorter.Sort();
List<string> expectedResults = new List<string>() { "E", "D", "B", "C", "A", "F", "G", "H" };
for(int i =0;i<sorter.SortResults.Count;i++)
{
Assert.AreEqual(expectedResults[i], sorter.SortResults[i]);
}
}