When I use the query
var NewMatchs = (from x in entity.matches select x).LastOrDefault();
I get error like this
LINQ to Entities does not recognize the method ‘SocialSports.Models.match
LastOrDefaultmatch’
method, and this method cannot be
translated into a store expression.
What’s wrong in my code ???
Thanks…
You can’t use LastOrDefault to query EF entities, as it cannot be translated to T-SQL.
Not all the LINQ methods are supported by Linq to Entities.
List of ALL supported / not supported methods:
http://msdn.microsoft.com/en-us/library/bb738550.aspx
You could try
but this will load ALL matches from the db and perform Linq to objects.
Or try sorting and call FirstOrDefault.