我试图根据他们的价格对产品列表进行排序。LINQ order by null column where order is up and nulls should last
结果集需要按列LowestPrice
列按价格从低到高列出产品。但是,此列可以为空。
我可以像这样降序排序列表:
var products = from p in _context.Products
where p.ProductTypeId == 1
orderby p.LowestPrice.HasValue descending
orderby p.LowestPrice descending
select p;
// returns: 102, 101, 100, null, null
但我无法弄清楚如何进行升序排列此。
// i'd like: 100, 101, 102, null, null
'的OrderBy p.LowestPrice? Int.MaxValue;'是一种简单的方法。 – PostMan
@PostMan:是的,它很简单,它达到了正确的结果,但是'OrderByDescending,ThenBy'更清晰。 – jason
@Jason,是的,我不知道'orderby'的语法,并得到了侧面追踪寻找:) – PostMan