LINQ to Entities无法识别使用LastOrDefault的方法

时间:2017-05-04 09:50:59

标签: c# .net asp.net-mvc linq

为什么我使用此LINQ表达式得到以下错误:

Models.Order last = context.Orders.LastOrDefault(o => o.customerID == customer.customerID);

而不是这个:

Models.Order last = context.Orders.Where(o => o.customerID == customer.customerID).OrderByDescending(o => o.orderID).ToList()[0];

错误:

System.NotSupportedException: LINQ to Entities does not recognize the
method 'Corporate.Models.Order LastOrDefault[Order](System.Linq.IQueryable`1
[Corporate.Models.Order], System.Linq.Expressions.Expression`1[System.Func`2
[Corporate.Models.Order,System.Boolean]])' method, and this method cannot be
translated into a store expression.

0 个答案:

没有答案