It appears a DbSet.Count() expression is getting evaluated ahead of time and parameterized.
Example:
var query = dbContext.MyDbSet.Select(v => new
{
v.Id,
Count = dbContext.MyDbSet.Count()
});
string sql = query.ToQueryString();
Expected:
SELECT [v].[Id], (select COUNT(1) from [MyTable]) AS [Count]
FROM [MyTable] AS [v]
Actual:
DECLARE @__Count_0 int = 20;
SELECT [v].[Id], @__Count_0 AS [Count]
FROM [MyTable] AS [v]
Maybe this is by design for some reason I'm not understanding. Thank you