这是SQL ORDER BY:
order by case when [order] is null then 1 else 0 end, [order]
如何在LINQ-To-Object语句中编写它?
答案 0 :(得分:3)
方法语法
var query = enumerable.OrderBy(x => x.order == null ? 1 : 0).ThenBy(x => x.order);
查询语法
var query = from x in enumerable
orderby (x.order == null ? 1 : 0), x.order
select x;
答案 1 :(得分:0)
假设订单是可以为空的值(不是对象),您应该能够使用它:
orderby null == order ? 1 : 0, order
如果是对象,可以尝试
orderby null == order ? 1 : 0, order.PropertyName