I have a Linq query which returns an ordered list. It works, but when sorting boolean values it always puts the false items first.
return from workers in db.Workers
orderby workers.active, workers.naam
select workers;
Is there a way to order the true items first?
Use the order by descending
option and it will reverse the list. See MSDN Soring Data for more examples on sorting.
return from workers in db.Workers
orderby workers.active descending, workers.naam
select workers;
The OrderBy method will sort items in ascending order by default. Now, given that the numeric representation of a boolean is:
false
= 0true
= 1false
values will naturally come first. If you want to reverse the order just use the descending
keyword:
return from workers in db.Workers
orderby workers.active descending, workers.naam
select workers;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With