The specific scenario I am trying to solve is to copy all the data in a LINQ to SQL data context. Because of the relations I need to copy the leaf nodes of the entity dependencies first so they exist before I add the entities that reference them.
Preferably I am looking for a library, alternatively an algorithm if there is a simple one.