Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq To Sql - Dynamic OrderBy - Case When

I'm using Linq to sql and Linq Dynamic OrderBy.

I know linq dynamic can do simple sorting like - orderby("column_name").

But does it support something more complex like queries with "CASE WHEN" in them ?

string orderbyQuery = "(CASE WHEN (username == 100) THEN 1 ELSE 0 END) DESC)";

here is my query :

var u = from u in db.users
        orderby(orderbyQuery)
        select u;

the above example doesn't work! , any idea if its possible? any other way to do it?

thanks

like image 961
dan Avatar asked Jan 06 '10 13:01

dan


1 Answers

var u = from u in db.users
        orderby u.username == 100 ? 1 : 0 descending
        select u;
like image 63
Dave D Avatar answered Nov 22 '22 15:11

Dave D