dotnet/efcore

Query: Stop producing N+1 queries for cases where single element subquery is projected inside a DTO

Closed this issue · 1 comments

As a consequence of fixing issue #7714 we are now producing N+1 queries for cases like:

customers.Select(c => new DTO { Count = c.Orders.Count() })

This is not necessary, because, even though parent query model needs client projection (because DTO is being used), the subquery returns a single result. We need to pass additional information to SqlTranslatingExpressionVisitor, so that it knows that the subquery that its currently processing returns a single result and that i can actually be fully translated into the parent query (unless something else forces client evaluation)

This is already fixed in dev branch - we are binding to parent query directly and never attempt to introduce the _outer parameters, closing