I have two tables: Category (Id, Name, ...) and Question (Id, CategoryId, Title, ...) with relation Category 1-* Question. I need to get the top three categories (with the highest number of questions) from the database.
I wrote this SQL query:
SELECT TOP 3 c.Name, COUNT(q.CategoryId)
FROM Category c
JOIN Question q
ON c.Id = q.CategoryId
GROUP BY Name
ORDER BY COUNT(q.CategoryId) DESC
and of course it works, but I need to write this query in LINQ. The main problem is in the first line with COUNT. How should I use it in this query?