I have a bit of EF Lambda code which returns a list of data from the db table, then orders by a field called
At first, the code was
var listOfData = Db .TableName .Where(u => u.UserId == userId) .OrderBy(u => u.IsDefault) .ToList();
Which when writing down, sounds correct. However is wrong as this will order by 0 > 1, and True = 1.
So I changed the statement to;
var listOfData = Db .TableName .Where(u => u.UserId == userId) .OrderBy(u => u.IsDefault ? 0 : 1) .ToList();
However, I could have also written this 2 other ways.
.OrderBy(u => !u.IsDefault)
.OrderByDescending(u => u.IsDefault)
Now in my mind,
u.IsDefault ? 0 : 1 reads better, and the other two could be misread as the not wanting the default value first.
What is your view on this?