`DbSet.Count()` in `Select()` lambda not translating to scalar subquery expression
Open
area-perf
area-query
customer-reported
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
It appears a DbSet.Count() expression is getting evaluated ahead of time and parameterized.
Example:
```csharp
var query = dbContext.MyDbSet.Select(v => new
{
v.Id,
Count = dbContext.MyDbSet.Count()
});
string sql = query.ToQueryString();
```
Expected:
```sql
SELECT [v].[Id], (select COUNT(1) from [MyTable]) AS [Count]
FROM [MyTable] AS [v]
```
Actual:
```sql
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
Contributor guide
Assessment
This issue has not been assessed yet.