views:

41

answers:

2

I have a 1 : M relationship.

I built a dynamic query based on input from users to return the listing of parents entities along with their children (using predicate builder:

(done successfully new TDataContext().Ps.Where(predicate) )...

but need to order the results by a field found only on the child entities.

I'm at a loss: new TDataContext().Ps.Where(predicate).OrderBy(p => p.Cs. ??)

where Ps = parents collection relationship with Cs = child entities

any help appreciated.

A: 

Try something like this:

new TDataContext().Ps.Where(predicate).OrderBy((<datatype of p> p) => p.Cs.Name)

You will have to replace "<datatype of p>" with whatever that is. Also, you will have to replace "Name" with whatever field you want to sort by.

Mikey
+1  A: 

One way would be to select childs first:

new TDataContext().Ps.Where(predicate).SelectMany(p=>p.Cs).OrderBy(q => q.Name);
Francisco