Solve the error LINQ to Entities does not recognize the method Last().
Hi all, in this post I will show you how to resolve a little problem when using ADO.net entity framework
Details of the problem: when trying to use the method last() to have the last record in the database table using thi code :
databaseEntities db = new databaseEntities(); UserSet user = new UserSet(); user = (from e1 in db.UserSet select e1).Last();
it throws an exception that says :
LINQ to Entities does not recognize the method ‘Myapp.UserSet Last[UserSet](System.Linq.IQueryable`1[Myapp.UserSet])’ method, and this method cannot be translated into a store expression.
Solution:
replace the instruction : user = (from e1 in db.UserSet select e1).Last(); with user = (from e1 in db.UserSet select e1).ToList().Last(); and it will work properly
Hope that was helpful.
Posted by ios developers on March 4, 2014 at 10:12 pm
Do you mind if I quote a few of your posts as long as I provide credit and sources back to your
blog? My website is in the very same niche as yours and
my users would genuinely benefit from some of the information you provide here.
Please let me know if this alright with you. Many thanks!
Posted by Yasmine Sefouane on March 5, 2014 at 1:57 pm
No problem, our purpose is sharing the little knowledge that we have, so you can quote the posts that you want.