linq query to select top 10 entries with most comments from the table linq query to select top 10 entries with most comments from the table asp.net asp.net

linq query to select top 10 entries with most comments from the table


That error message is because you are calling .Count() on a string property (QUEST_TEXT). That compiles because strings are enumerable. However, Linq-to-SQL doesn't understand this.

If you have the relationship between the two tables mapped in your DBML file, then you can use it in your expression:

var top = (from q in db.question_tables           orderby q.answers.Count() descending           select q).Take(10);

However the code you posted doesn't quite match the description you gave. You mention comments, but the code talks about answers.


Join Posts and Comments, order by Post.Comment count descending and the take the top 10.

(from p in Postsfrom c in Commentswhere c.PostId == p.Idorderby p.Comments.Count() descendingselect p).Take(10);

EDIT

From your edits, it looks like you are trying to find the question with the longest QUEST_TEXT value. If that is what you need, just change your code to orderby q.QUEST_TEXT.Length descending, but that doesn't sound like what you originally asked.