SQL TO LINQ
Options
Hi
SELECT *
FROM Purchase
WHERE Price > 10
ORDER BY
CASE WHEN Price > 1500 THEN Price END DESC,
CASE WHEN Price <= 1500 THEN Price END ASC
How to express this SQL into
IQueryable orderedQuery = .... ?
Any help would be appreciate it. Thanks!
Reiner
SELECT *
FROM Purchase
WHERE Price > 10
ORDER BY
CASE WHEN Price > 1500 THEN Price END DESC,
CASE WHEN Price <= 1500 THEN Price END ASC
How to express this SQL into
IQueryable orderedQuery = .... ?
Any help would be appreciate it. Thanks!
Reiner
Comments
-
Very strange ordering, but I guess the following should work
var query = Purchase
or even
.Where(a => a.Price > 10)
.OrderByDescending(a=>a.Price > 1500 ? a.Price : 0)
.ThenBy(a=> a.Price < 1500 ? a.Price : 0);var query = Purchase
.Where(a => a.Price > 10)
.OrderBy(a => a.Price > 1500 ? (0 - a.Price) : a.Price);