sql order by - Linq orderby two-column sort with custom comparer -
list<myobject> objects = (from in alist join b in blist on a.id equals b.id a.number != 4 orderby b.rank, a.customfield select a).tolist();
this query , want use custom comparer customfield property. there way in two-field orderby?
i able this:
list<myobject> objects = objects.orderby(a => a.customfield, new mycomparer<object>())
but need sorted both s.rank , a.customfield.
use orderby()
in conjunction thenby()
custom comparers.
// i'm pretty sure not possible specify // custom comparer within query expression list<myobject> objects = (from in alist join b in blist on a.id equals b.id a.number != 4 select new { a, b }) .orderby(o => o.b.rank, new myrankcomparer()) .thenby(o => o.a.customfield, new mycomparer<object>()) .select(o => o.a) .tolist();
Comments
Post a Comment