I have following two tables:
1.) Articles - [ArticleID]
2.) ArticleComments - [CommentID], [ArticleID]
I want to retrieve ArticleID with maximum no. of comments e.g.
ArticleID - 2
TotalNoOfComments - 15
How do I do it in Entity Framework?
I access ArticleComments collection like following: article.ArticleComments. The following will be the object to store the result.
public class CommentStats
{
public int ContextId { get; set; }
public int CommentCount { get; set; }
}
You can then run
FirstOrDefaultfor the one article with most comments, orToListfor the whole ordered list.