In LINQ, is it possible to have conditional orderby sort order (ascending vs. descending).
Something like this (not valid code):
bool flag; (from w
If the ordering property Id is a number (or supports the unary minus) one could also do:
Id
bool ascending = ... collection.Where(x => ...) .OrderBy(x => ascending ? x.Id : -x.Id) .Select(x => ...) // LINQ query from x in ... orderby (ascending ? x.Id : -x.Id) select ...