Imagine that you have Entity Framework entities that look like this (obviously, not these specific classes, but autogenerated with all Entity Framework plumbing, this is just for illustration):
public class Parent { public int ID { get; set; } public List<Child> Children { get; set; } } public class Child { public int ID { get; set; } public Parent Parent { get; set; } public int Number { get; set; } }
I have a LINQ query that looks like this:
from parent in context.Parents.Include("Child") select parent
However, this returns a list of parents in which the children are in input order. I want children to be sorted by their number in their parent. How can I do that?
Edit:. Clarification: The idea is to hide the request behind a method call (on the facade of the layer), which simply returns an IList<Parent> . This makes using solutions like anonymous class queries and manual sorting painful (compared to some panacea solutions where you can just do it in a query or something like that).
c # linq linq-to-entities
Daniel Chambers
source share