title: How to write a select count group by SQL query in LINQ?
body: <p>I have this query which works but when I try to write the equivalent in LINQ I get the incorrect SQL produced.</p>
  
  <p>My query is:</p>
  
  <pre><code>SELECT COUNT(*)
  FROM tableName
  GROUP BY ColumnId
  </code></pre>
  
  <p>I've tried writing it as:</p>
  
  <pre><code>tableName.GroupBy(x =&gt; x.ColumnId).Count()
  </code></pre>
  
  <p>But looking in LINQPad it is producing the SQL:</p>
  
  <pre><code>SELECT COUNT(*) AS [value]
  FROM (
  SELECT NULL AS [EMPTY]
  FROM [tableName] AS [t0]
  GROUP BY [t0].[ColumnId]
  ) AS [t1]
  </code></pre>
  
  <p>What am I doing wrong? Thanks!</p>