LINQ Orderby 降序查询 [英] LINQ Orderby Descending Query
问题描述
我相信这将是一个相对简单的.
I'm sure this will be a relatively simple one.
我有一个 LINQ 查询,我想按最近创建的日期排序.
I have a LINQ query that I want to order by the most recently created date.
见:
var itemList = from t in ctn.Items
where !t.Items && t.DeliverySelection
orderby t.Delivery.SubmissionDate descending
select t;
我也试过:
var itemList = (from t in ctn.Items
where !t.Items && t.DeliverySelection
select t).OrderByDescending();
但这会产生错误:
方法没有重载'OrderByDescending' 需要 0 个参数
No overload for method 'OrderByDescending' takes 0 arguments
从我所读到的内容来看,我相当确定我采用的第一种方法应该可行.我尝试将降序更改为升序,只是为了查看它是否有任何作用,但它保持不变.
From what I've read, I'm fairly sure the first way I've done it should work. I've tried changing descending to ascending just to see if it does anything but it stays the same.
如果有人可以查看查询并查看我是否做错了什么,我将不胜感激.谢谢:)
I'd be grateful if someone could take a look at the query and see if I'm doing anything wrong. Thanks :)
推荐答案
您需要选择一个属性进行排序并将其作为 lambda 表达式传递给 OrderByDescending
You need to choose a Property to sort by and pass it as a lambda expression to OrderByDescending
喜欢:
.OrderByDescending(x => x.Delivery.SubmissionDate);
<小时>
确实,虽然您的 LINQ 语句的第一个版本应该可以工作.t.Delivery.SubmissionDate
是否实际填充了有效日期?
Really, though the first version of your LINQ statement should work. Is t.Delivery.SubmissionDate
actually populated with valid dates?
这篇关于LINQ Orderby 降序查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!