SQL TO LINQ

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

Comments

  • Very strange ordering, but I guess the following should work
     var query = Purchase
    .Where(a => a.Price > 10)
    .OrderByDescending(a=>a.Price > 1500 ? a.Price : 0)
    .ThenBy(a=> a.Price < 1500 ? a.Price : 0);
    or even
    var query = Purchase
    .Where(a => a.Price > 10)
    .OrderBy(a => a.Price > 1500 ? (0 - a.Price) : a.Price);
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!