1

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.

Renshai
  • 89
  • 1
  • 6

2 Answers2

1

One way would be to select childs first:

new TDataContext().Ps.Where(predicate).SelectMany(p=>p.Cs).OrderBy(q => q.Name);
Francisco
  • 4,104
  • 3
  • 24
  • 27
0

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
  • 2,837
  • 2
  • 18
  • 17