How do I order by child objects in LINQ?
Classes A, B, and C. A has a collection of B and B has a collection of C. I want to order object A by the Ordinal (int) property of C.
var query = from a in db.A
orderby a.Bs.OrderBy(x=> x.C.Ordinal) <--- ??
select a;
I can't seem to figure out the orderby statement for this.
EDIT:
Sorry, my original statement was incorrect:
A has a collection of B and B holds a C object. C is not a collection.
Each A should be ordered on C's ordinal property.
ANOTHER EDIT/Solution:
I ended up doing an .OrderBy(b=>b.C.Ordinal) on the client for each B collection in A during display. That turned out better anyway since I can let the client order by anything they need to, instead of embedding that in my repository.