title: LINQ - Left Join, Group By, and Count
body: <p>Let's say I have this SQL:</p>
  
  <pre><code>SELECT p.ParentId, COUNT(c.ChildId)
  FROM ParentTable p
    LEFT OUTER JOIN ChildTable c ON p.ParentId = c.ChildParentId
  GROUP BY p.ParentId
  </code></pre>
  
  <p>How can I translate this into LINQ to SQL? I got stuck at the COUNT(c.ChildId), the generated SQL always seems to output COUNT(*). Here's what I got so far:</p>
  
  <pre><code>from p in context.ParentTable
  join c in context.ChildTable on p.ParentId equals c.ChildParentId into j1
  from j2 in j1.DefaultIfEmpty()
  group j2 by p.ParentId into grouped
  select new { ParentId = grouped.Key, Count = grouped.Count() }
  </code></pre>
  
  <p>Thank you!</p>