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

Multiple queries being generated when entire element selected #14326

Closed
meyerovb opened this issue Jan 5, 2019 · 2 comments
Closed

Multiple queries being generated when entire element selected #14326

meyerovb opened this issue Jan 5, 2019 · 2 comments

Comments

@meyerovb
Copy link

meyerovb commented Jan 5, 2019

EF is producing multiple queries (n+1) instead of a single query with a subquery when the selection contains the entire element instead of just part of it.

Steps to reproduce

Set up a project as per https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db?tabs=visual-studio

context.Blogs.Select(a => new { a.Url, a.Posts.Count }).ToList();

runs this

SELECT [a].[Url], (
    SELECT COUNT(*)
    FROM [Posts] AS [p]
    WHERE [a].[BlogId] = [p].[BlogId]
) AS [Count]
FROM [Blogs] AS [a]
context.Blogs.Select(a => new { a, a.Posts.Count }).ToList();

runs this

SELECT [a].[BlogId], [a].[Url]
FROM [Blogs] AS [a]

exec sp_executesql N'SELECT COUNT(*)
FROM [Posts] AS [p0]
WHERE @_outer_BlogId = [p0].[BlogId]',N'@_outer_BlogId int',@_outer_BlogId=2

Further technical details

EF Core version: 2.2
Database Provider: mssqllocaldb
Operating system: Win10
IDE: (e.g. Visual Studio 2017 15.9.4)

@ajcvickers
Copy link
Member

@smitpatel to find dupe.

@smitpatel
Copy link
Contributor

Duplicate of #11186

@smitpatel smitpatel marked this as a duplicate of #11186 Jan 7, 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