efcore: ArgumentOutOfRangeException upon certain queries with includes
Certain queries with includes are causing an ArgumentOutOfRangeException.
When using OData, almost (or possibly) all queries with more than one expand of a collection and translating to SQL fails with the following error:

Steps to reproduce
A very quick repro, download this zip, extract it in the src folder, open All.sln, add the zipped project as an existing project, make sure the project references are set correctly and run. It will create a local SQL database on your machine. And it will fail to run the following query:
http://localhost:15580/odata/Movies?$expand=Stars,Writers
If you remove either one of the expands, it works. I wasn’t sure whether to post to OData or here, but I think the issue lies here.
Further technical details
EF Core version: 3.1.1 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET Core 3.0 Operating system: Windows 10 IDE: Visual Studio 2019 16.5 Preview 1
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 8
- Comments: 24 (10 by maintainers)
Commits related to this issue
- Query: Map projection properly when joining 2 tables When joining 2 tables in relational, we lift the table from inner select expression and copy over projections. If one of this projection is same a... — committed to dotnet/efcore by smitpatel 4 years ago
- Query: Map projection properly when joining 2 tables When joining 2 tables in relational, we lift the table from inner select expression and copy over projections. If one of this projection is same a... — committed to dotnet/efcore by smitpatel 4 years ago
- Query: Map projection properly when joining 2 tables When joining 2 tables in relational, we lift the table from inner select expression and copy over projections. If one of this projection is same a... — committed to dotnet/efcore by smitpatel 4 years ago
- Query: Map projection properly when joining 2 tables When joining 2 tables in relational, we lift the table from inner select expression and copy over projections. If one of this projection is same a... — committed to dotnet/efcore by smitpatel 4 years ago
- Query: Map projection properly when joining 2 tables When joining 2 tables in relational, we lift the table from inner select expression and copy over projections. If one of this projection is same a... — committed to dotnet/efcore by smitpatel 4 years ago
Could this please be fixed and released ASAP? Right now this is blocking anyone that relies on OData from upgrading to .NET Core 3.1. We cannot upgrade our APIs, because client apps are doing multiple expands against our endpoints, which apparently no longer work because of this bug.
So we’re essentially stuck on the - now deprecated - .NET Core 2.2 until this is fixed.
@nikolai-mb Yes, @smitpatel will take over here.
This is also a blocker for our application upgrade to 3.1, desperately waiting for a fix.
👍 I must apologize, after upgrading all my nugget packages (Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.SqlServer), the 3.1.4 release solves it. I’m an happy camper now. Thank you very much, you did an awesome job guys !
@gunter79 We may have missed something, or you may be hitting a different bug. Please file a new issue and attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
@jannikbuschke I’m not at liberty to give an exact date, but it is planned for this month.
I’m with @cornem , I’m completely blocked by this. OData calls that were fine in 2.2 are now seeing “No coercion operator is defined between types ‘System.Int32’ and ‘System.Boolean’” and " Index was out of range. Must be non-negative and less than the size of the collection." errors.