0

Why I get the error below with this LINQ expression:

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

And not with this:

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

Error:

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.
abenci
  • 8,422
  • 19
  • 69
  • 134

0 Answers0