LINQ to Entities query generating odd error?

The reason why it fails is because the entities are not yet loaded and Last() will be called on sql not on the generic list. So first you need to load them up before asking for Last(). The first example might have worked because the board already had a loaded generic list Try the following: topics = (from x in DBContext.Topics.AsEnumerable() let lastActivityDate = (x.Replies.Any()?X.Replies.

OrderBy(y => y. PostedDate).Last(). PostedDate : x.

PostedDate) where x. BoardID == boardID where lastActivityDate > lastTopic. PostedDate orderby lastActivityDate select x).ToList() Refer to: Supported and Unsupported LINQ Methods (LINQ to Entities).

The reason why it fails is because the entities are not yet loaded and Last() will be called on sql not on the generic list. So first you need to load them up before asking for Last(). The first example might have worked because the board already had a loaded generic list.

Try the following: topics = (from x in DBContext.Topics.AsEnumerable() let lastActivityDate = (x.Replies.Any()? X.Replies. OrderBy(y => y.

PostedDate).Last(). PostedDate : x. PostedDate) where x.

BoardID == boardID where lastActivityDate > lastTopic. PostedDate orderby lastActivityDate select x).ToList(); Refer to: Supported and Unsupported LINQ Methods (LINQ to Entities).

– Jani Jan 9 at 6:39 @Jani: Updated the answer with more context. – Mahesh Velaga Jan 9 at 6:41 @Mahesh that could hurts dude, you loaded all the topics in memory, it's a very expensive solution for DBMS and also Application Server, that couldn't be a good idea – Jani Jan 9 at 6:43 @Jani: Agreed, trying to show why its not working, rather than giving an optimal way. – Mahesh Velaga Jan 9 at 6:46 @Jani: Updated the query.

– Mahesh Velaga Jan 9 at 7:03.

That query works great. Every time the page loads the topics are ordered correctly. Can anyone see anything wrong with this LINQ query?

LINQ to Entities does not recognize the method 'MyProject.Models. Reply LastReply (System.Collections.Generic. Reply)' method, and this method cannot be translated into a store expression.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions