LINQ Orderby降序查询
我相信这将是一个相对简单的。
我有一个LINQ查询,我想按最近创build的datesorting。
看到:
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个参数
从我读过的内容来看,我相当确定我做的第一个方法应该可行。 我已经尝试改变下降升序只是为了看看它做了什么,但它保持不变。
如果有人可以看一下查询,看看我是否做错了,我将不胜感激。 谢谢 :)
 您需要select一个属性进行sorting,并将其作为一个lambdaexpression式传递给OrderByDescending 
喜欢:
 .OrderByDescending(x => x.Delivery.SubmissionDate); 
 真的,尽pipe你的LINQ语句的第一个版本应该工作。  t.Delivery.SubmissionDate实际上填充有效的date? 
我认为这是第一次失败,因为你订购的价值是空的。 如果Delivery是一个外键关联表,那么你应该首先包含这个表,例如下面的例子:
 var itemList = from t in ctn.Items.Include(x=>x.Delivery) 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(c => c.Delivery.SubmissionDate);