I have this query that works, but when I try to write the equivalent in LINQ, I get the wrong SQL.
My request:
SELECT COUNT(*) FROM tableName GROUP BY ColumnId
I tried to write it as:
tableName.GroupBy(x => x.ColumnId).Count()
But, looking in LINQPad, it produces SQL:
SELECT COUNT(*) AS [value] FROM ( SELECT NULL AS [EMPTY] FROM [tableName] AS [t0] GROUP BY [t0].[ColumnId] ) AS [t1]
What am I doing wrong? Thanks!
linq-to-sql
Kevin
source share