tags:

views:

45

answers:

5

Let's say I have a linq query like the one below

var LinqResult =
    from a in Db.Table
    select new {Table = a};

From here, how can I grab a specific row from these results and put it on top?

A: 

Add

 orderby a.Id == someId // or some other condition
Daniel A. White
A: 

If you already know which row you want on top based on say an id, you could try ordering based on that rows id.

var LinqResult =
    from a in Db.Table
    orderby a.Id == checkId descending
    select new {Table = a};
Kevin Wiskia
A: 

put where conition betweem from and select assuming that Db.Table is having ID column and having rows greater than 10

var LinqResult = 
from a in Db.Table 
where a.ID > 10
select new {Table = a}; 
saurabh
A: 
 orderby (a.Id == someId ? 1 : 2)

That make the ordering rather explicit, by sorting on the numbers 1 or 2, depending on whether or not it's the desired top value.

You could simplify that a bit, by sorting on the bool expression itself, except false < true, so to get someId on top, you must either write:

 orderby a.Id != someId

or

 orderby a.Id == someId descending
James Curran
Awesome, very helpful to know this thanks!!!
Soo
A: 

you can try

var LinqResult =
    (from a in Db.Table
    select new {a.column}).Orderby();
anishmarokey