Placing where
after group by
in LINQ to SQL, works like having
in T-SQL. I hope that LINQ generates having
statement in result. but when I look at the output statement, I don't see any having
statement. Is there any method or trick to force LINQ to use having
, and for better performance?
LINQ query:
var result = from item in db.Words
group item by item.UserID into gp
where gp.Average(g => g.DownVotes) == 0
select gp.Key;
result.ToList();
SQL output:
-- Region Parameters
DECLARE @p0 Float = 0
-- EndRegion
SELECT [t1].[UserID]
FROM (
SELECT AVG([t0].[DownVotes]) AS [value], [t0].[UserID]
FROM [Words] AS [t0]
GROUP BY [t0].[UserID]
) AS [t1]
WHERE [t1].[value] = @p0
I think this query has low performance vs having