Could you explain why LastOrDefault doesn't works where FirstOrDefault do the job without any problem. It seems these 2 methods are not the same:
Ont his example from LinqPad:
var varone = Guid.Parse("bbb3d139-fbec-430c-9574-02f3412c95df");
Price.Where(y => y.Id == varone && y.ApplicationDate.Value <= new DateTime(2016,06,01))
.OrderByDescending(y => y.ApplicationDate.Value)
.LastOrDefault().Dump();
I get a
NotSupportedException: LINQ to Entities does not recognize the method 'Nppg.Core.BusinessModels.BeperEntities.Price LastOrDefaultPrice' method, and this method cannot be translated into a store expression.
But no problem if I replace LastOrDefault by FirstOrDefault
var varone = Guid.Parse("bbb3d139-fbec-430c-9574-02f3412c95df");
Price.Where(y => y.Id == varone && y.ApplicationDate.Value <= new DateTime(2016,06,01))
.OrderByDescending(y => y.ApplicationDate.Value)
.FirstOrDefault().Dump();