I have a LINQ from SQL query that returns sorted rows. For instance, it will return: 1 1开发者_运维百科 1 1 1 1 1 1 2 2 2 3 3 3 3 3 4 4 4 4 I am looking for a way to tell the LINQ to cut & paste all the 1's and place it after the 3's, so it will look 2 2 2 3 3 3 3 3 1 1 1 1 1 1 1 4 4 4 4 .
What is the most efficient way to relocate its pointers? (without selecting & deleting & copying)
thanks
Try
query.OrderBy(x => x == 1 : 3.5 ? (float)x);
Try this:
var list = <YourLinqQuery>.ToList();
var sortedList = list.OrderBy(a=> (a==1)? 3.5:a);
I would do it in the Linq to SQL query like so:
var query = from x in context.Table
let Order = x.RowNum == 1 ? 3.5 : x.RowNum
orderby Order
select x;
精彩评论