ASP.NET forum app: obtaining the answer with most likes

We are building a forum type web application, and we are tring to make the answers with most likes (and most dislikes) look different. The Answer entity has a Reactions property (list of reactions) that include likes and dislikes (those are differentiated with a boolean property, true for like, false for dislike). Is there a way to obtain the answer with most likes, and the answer with most dislikes, with a LINQ query directly? or we have to make a method that solves it?

EDIT: I have only one entity “Reactions” That represents both Likes and Dislikes. The only difference between the two of them, is a boolean property set on true for likes, and false on dislikes

Thanks!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

EDIT: Based on Sajid’s comment, the query was simplified:

Of course:

reactions.Where(liked => Liked.IsLike && (liked.id = 123)).Count()

or even
reactions.Count(liked => liked.IsLike && liked.id == 123)


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x