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

Can not work with EF Core 5 AsSplitQuery() #2380

Closed
anranruye opened this issue Dec 11, 2020 · 1 comment
Closed

Can not work with EF Core 5 AsSplitQuery() #2380

anranruye opened this issue Dec 11, 2020 · 1 comment
Assignees

Comments

@anranruye
Copy link

anranruye commented Dec 11, 2020

OData WebApi can not work with EF Core 5 AsSplitQuery() api when expand navigation collections.

Assemblies affected

Microsoft.AspNetCore.OData 7.5.2
Microsoft.EntityFrameworkCore 5.0.1
Microsoft.EntityFrameworkCore.SqlServer 5.0.1

Reproduce steps

Call AsSplitQuery() before transfer the IQuerable object to OData WebApi and run any query which expand one or more navigation collections.

Expected result

The query works well and ef core perform separate sql query for each navigation collection.

Actual result

EF Core 5 can not understand the query produced by OData WebApi and throw an error.

Additional detail

In the error message, ef core suggest that single sql query should be used. However, when single sql query loads multiple collections, it may cause performance issues.

EF Core 5 provides QuerySplittingBehavior and AsSingleQuery()/AsSplitQuery() to let the user decide whether to perform single sql query or separate sql queries. But it can not translate the Linq query produced by OData WebApi to separate sql queries in this moment.

The same Linq query produced by OData WebApi can work with EF Core 2.x which can only perform separate sql queries. But EF Core 2.x can not create single sql query, this may also cause performance issues sometimes. And we don't want to fallback to EF Core 2.x since EF Core 5 is obviously more powerful than 2.x version in many ways.

ps: I use Sql Server database, not sure the situation with other data providers this moment.

@anranruye
Copy link
Author

Closing this since this is an problem of ef core. It seems that OData can not do better to improve.

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