I'm getting an error when using the following code
var v1 = from P in db1.QuranWordsNews where P.Aye == perId select P;
var vv = v1.LastOrDefault(); // The error occurs here
The message:
LINQ to Entities does not recognize the method 'TashihQuran.QuranWordsNew LastOrDefaultQuranWordsNew' method, and this method cannot be translated into a store expression.
Maybe the better answer is here :
var vv = v1.OrderByDescending(rec => rec.Id).FirstOrDefault();
Fetch all records from database to use just the last record is not good.
I guess you're still working in IQueriable
. Try instead
var vv = v1.ToList().LastOrDefault();
or, more elegant
var vv = v1.AsEnumerable().LastOrDefault();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With