我有這個查詢哪些工作,但是當我嘗試在LINQ中寫入等價物時,我得到了生成的不正確的SQL。如何在LINQ中通過SQL查詢編寫select count組?
我的查詢是:
SELECT COUNT(*)
FROM tableName
GROUP BY ColumnId
我試圖寫它:
tableName.GroupBy(x => x.ColumnId).Count()
但看在LINQPad它產生SQL:
SELECT COUNT(*) AS [value]
FROM (
SELECT NULL AS [EMPTY]
FROM [tableName] AS [t0]
GROUP BY [t0].[ColumnId]
) AS [t1]
我是什麼做錯了?謝謝!