0

Is there any way to perform an OrderBy with an aggregated field (string.Join)?

var query = <Some IQueryable<T>>;
    
query = query.OrderBy(x => string.Join(",", x.Values.Select(v => v.Name)));

I am building dynamic queries and came up a need to order by a column that is agreggated like the above example.

Thanks in advance

1 Answers1

0

You need to first project the aggregated column before you can do OrderBy.


    query = query.Select(x=>new {
    Item = x,
    Agg = x => string.Join(",", x.Values.Select(v => v.Name))
    }).OrderBy(a=>a.Agg).Select(a=>a.Item)

Ayush Jain
  • 57
  • 2