这是 SQL ORDER BY:
order by case when [order] is null then 1 else 0 end, [order]
如何在 LINQ-To-Object 语句中编写它?
这是 SQL ORDER BY:
order by case when [order] is null then 1 else 0 end, [order]
如何在 LINQ-To-Object 语句中编写它?
方法语法
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;
假设 order 是一个可为空的值(不是对象),您应该可以使用它:
orderby null == order ? 1 : 0, order
如果它是一个对象,你可以尝试
orderby null == order ? 1 : 0, order.PropertyName