title: How to write this SQL query as a LINQ statement in .NET Core (C#)?
body: <p>I'm trying to join three tables together, but I just can't get my LINQ statements to get the data I want to. My SQL query that I want to replicate is like this: </p>
  
  <pre><code>SELECT TOP 5 SUM(Grade) AS 'TotalGrade', COUNT(Restaurants.Name) AS 'NumberOfVisits', Restaurants.Name FROM Lunches
    JOIN dbo.LunchRestaurant ON Lunches.LunchId = LunchRestaurant.LunchId
    JOIN Restaurants ON Restaurants.RestaurantId = LunchRestaurant.RestaurantId
    GROUP BY Restaurants.Name
  </code></pre>
  
  <p>The LINQ statement I currently have is: </p>
  
  <pre><code>    var q = from l in lunchContext.Lunches
              join lr in lunchContext.LunchRestaurant on l.LunchId equals lr.LunchId
              join r in lunchContext.Restaurants on lr.RestaurantId equals r.RestaurantId
              select new { l.Grade, r.RestaurantId};
  </code></pre>
  
  <p>But with this one, I can't get in my group by statement or the aggregate functions no matter how I try. Do you have any suggestions on what to do? There also doesn't seem to be a way to write raw SQL statements when dealing with several tables, at least not easily done in EF Core if I'm not mistaken. Otherwise that'd be an option too.</p>