LINQ排序依据降序查询 [英] LINQ Orderby Descending Query

查看:382
本文介绍了LINQ排序依据降序查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,这将是一个比较简单的。

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();

但是这给出了一个错误:

but this gives an error :

没有过载方法
  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前pression到<一个href=\"https://msdn.microsoft.com/en-us/library/bb534855(v=vs.100).aspx\"><$c$c>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排序依据降序查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆