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

"The query has been configured to use 'QuerySplittingBehavior.SplitQuery' and contains a collection in the 'Select' call" #22868

Closed
aradalvand opened this issue Oct 2, 2020 · 8 comments

Comments

@aradalvand
Copy link

aradalvand commented Oct 2, 2020

Please tell me if this is a duplicate, but:

I want to avoid the "Cartesian Explosion Problem", I noticed that EF Core 5.0 has now the option to enable "split queries".

However, I found out that it's not possible to use split queries when collections are projected:

var result = dbContext.Products.AsSplitQuery().Select(p => new BookDto
    {
        Name = p.Name,
        Rates = p.Ratings.Select(r => new RatingDto { Rate = r.Rate }).ToList(),
    }).ToList();

This would cause the following exception to be thrown:

"The query has been configured to use 'QuerySplittingBehavior.SplitQuery' and contains a collection in the 'Select' call, which could not be split into separate query. Please remove 'AsSplitQuery' if applied or add 'AsSingleQuery' to the query."

Why isn't this possible? It seems perfectly reasonable!
I'm not sure but I believe this used to work in EF Core 2.x

Will this be implemented? It is very much needed! Thank you!

Provider and version information:

EF Core version: 5.0.0 RC1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0

@ilmax
Copy link
Contributor

ilmax commented Oct 2, 2020

I just updated to 5 RC1 to test it out in our application and I'm hitting this one a lot.
My scenario is a bit different, I configured the context to use the UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery) and then I have a query similar to the following one:

var result = context.Products.Select(p => new ProductDto
    {
        Name = p.Name,
        Rates = p.Ratings.Select(r => new RatingDto { Rate = r.Rate }).ToList(),
    }).ToList();

My expectation was that setting UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery) could revert the query behavior to what EF Core 2.2 was doing, related to Include and ThenInclude but I'm either missing something or that's not the case.

I got the exception, but at this point I have choose between changing all the queries (that will just fail at runtime) and add .AsSingleQuery() or keep the cartesian explosion issue introduced in 3.1.

Am I missing something?

@smitpatel
Copy link
Contributor

Duplicate of #21234

@smitpatel smitpatel marked this as a duplicate of #21234 Oct 2, 2020
@aradalvand
Copy link
Author

aradalvand commented Oct 5, 2020

@smitpatel
I know you guys are truly busy, but can you tell us sir approximately when are you planning to implement this?
Since this is a somewhat necessary part of a feature that was brought back, I'd say it makes sense if it too is hopefully brought back (or implemented) soon.
Thanks in advance.

@aradalvand
Copy link
Author

aradalvand commented Oct 5, 2020

@ilmax Well, no, you're not missing anything. EF Core 3+ just doesn't have that feature yet.
Please upvote this issue #21234 if you too need this feature.

@aradalvand
Copy link
Author

aradalvand commented Oct 7, 2020

@smitpatel Could you please answer my question 👆 I'd appreciate it

@smitpatel
Copy link
Contributor

Follow #21234 for updates. That issue is in backlog milestone hence it is not going to happen for 5.0. We will consider it for next release.

@aradalvand
Copy link
Author

aradalvand commented Oct 7, 2020

@smitpatel

We will consider it for next release.

Okay, sounds great, it'd be awesome if it'll be added in the next release.

Thanks.

@johnkwaters
Copy link

I am really upset by this. I have been waiting ever since 2.2 for AsSplitQuery. And now that it's here, it can't handle the use case where it's needed! I fetch a deep object graph off my Trip object with the following includes:

{
"CurrentBreadcrumb",
"Route",
"Route.Driver",
"Route.StartsAt",
"Route.StartsAt.TimeZone",
"Stops",
"Stops.Location",
"Stops.Location.TimeZone",
"Stops.Location.Address",
"Stops.Location.Address.State",
"Driver",
"Legs",
"Stops.Activities",
"Stops.Activities.ActivityType",
"Stops.Activities.Properties",
"Stops.Activities.SurveyResult",
"Stops.Activities.Survey",
"TripErrors",
"TripErrors.Stop",
"Metrics"
});

2.2 did it fast. 3.0. 3.1 and 5.0 use tons of memory and take a minute. SplitQuery wont process it. Am I supposed to hand code all of the parts of assembling this tree? What's the point of an ORM then? Why did you remove this feature and not add back any compatibility?

@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

5 participants