Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: projecting anonymous type containing entity and subquery returning a scalar results in N+1 queries #8083

Closed
maumar opened this issue Apr 5, 2017 · 1 comment

Comments

@maumar
Copy link
Contributor

maumar commented Apr 5, 2017

Repro:

                var query = from g in ctx.Gears
                            where g.HasSoulPatch
                            orderby g.Nickname
                            select new { Gear = g, WeaponsCount = g.Weapons.Count };

produces:

SELECT [g].[Nickname], [g].[SquadId], [g].[AssignedCityName], [g].[CityOrBirthName], [g].[Discriminator], [g].[FullName], [g].[HasSoulPatch], [g].[LeaderNickname], [g].[LeaderSquadId], [g].[Rank]
  FROM [Gear] AS [g]
  WHERE [g].[Discriminator] IN (N'Officer', N'Gear') AND ([g].[HasSoulPatch] = 1)
  ORDER BY [g].[Nickname]
  
  @_outer_FullName: Damon Baird (Size = 450)
  
  SELECT COUNT(*)
  FROM [Weapon] AS [w0]
  WHERE @_outer_FullName = [w0].[OwnerFullName]
  
  @_outer_FullName: Marcus Fenix (Size = 450)
  
  SELECT COUNT(*)
  FROM [Weapon] AS [w0]
  WHERE @_outer_FullName = [w0].[OwnerFullName]

We should be able to produce a single query, and we do, if instead of gear we project it's properties individually.

@smitpatel
Copy link
Member

Duplicate of #11186

@smitpatel smitpatel marked this as a duplicate of #11186 May 2, 2019
@smitpatel smitpatel removed this from the Backlog milestone May 2, 2019
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants