I have collections of entities that I need to sort depending on their dependencies to each other. Here's an example because it's fairly tough to explain:
public class A {
private B objB;
public B propB { get{ return objB; } }
// Some other fields and properties.
}
public class B { /* Some fields and properties. */ }
The thing is that I need to import data into collections of those types but I need to import in a certain order because if I import A
objects first, I will not be able to link the corresponding B
since it won't exist yet.
So what I'd like is to sort my collections in a way that all dependencies are imported in the right order (There are no circular dependencies). I can't figure out a linq statement that will do that though.
lists.OrderBy(l => l. ??? );
I was thinking maybe get a list typesList
of all the types T
of the List<T>
in lists
and somehow use reflection to count how many fields in T
are in typesList
but that seems... inefficient ?
Aucun commentaire:
Enregistrer un commentaire