title: LINQ-Entities Group By With Range Variable Query
body: <p>Here's my T-SQL which i'm trying to convert to a LINQ-Entities query....</p>
  
  <pre><code>SELECT  [a].[ModLimit], [b].[NumberOfMods]
  FROM    [dbo].[Site][a]
  INNER JOIN
  (
      SELECT          [SiteId], ISNULL(COUNT(*),0) AS [NumberOfMods]
      FROM            [dbo].[Users][a]
      WHERE           [a].[IsMod] = 1
      GROUP BY        [SiteId]
  ) [b] ON [a].[SiteId] = [b].[SiteId]
  WHERE   [a].[SiteId] = 1
  </code></pre>
  
  <p>What i'm working with so far (not compiling...)</p>
  
  <pre><code>from u in db.Set&lt;User&gt;()
  join s in db.Set&lt;Site&gt;() on u.SiteId equals s.SiteId
  let x = t.ModLimit
  where s.SiteId == 1
  group u by u.SiteId into g
  select new { g,x});
  </code></pre>
  
  <p>Ideas?</p>
  
  <p>Cutdown Structure of tables:</p>
  
  <p><strong>Site</strong></p>
  
  <p><em>SiteId</em> int PK</p>
  
  <p><em>ModLimit</em> int</p>
  
  <p><strong>Users</strong></p>
  
  <p>UserId int PK</p>
  
  <p><em>SiteId</em> int FK
  <em>IsMod</em>  bit</p>