-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Known limitation: Invalid SQL is produced in v4.x #922
Comments
Thanks for the writeup. Experiencing this with nested requests for "HasOne" relationships, on 4.1.1, e.g.
...where Disabling paging seems to have resolved it. I don't see the behavior requesting nested HasMany relationships. |
@bart-degreed, thanks for documenting this so nicely. I've run into the same issue. The reported error was like your second bullet (invalid column name). I've successfully used the first workaround. |
Closing, as there's nothing we can do to make this work on old versions. The bug was fixed in EF Core 6. |
Symptons
When using certain kinds of relationships in combination with both top-level and nested paging, EF Core produces an invalid SQL statement. This bug in EF Core is tracked here.
Publicly logged cases:
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'near \"(\": syntax error'.
Sqlite with many-to-many relationship, Include Query Error Not Working #861
Microsoft.Data.SqlClient.SqlException: Invalid column name 'RoleId'
SQL Server with many-to-many relationship, Malformed Query when GetAsync() and including a navigation collection with HasManyThrough #884
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'near \"(\": syntax error'.
Sqlite with one-to-many relationship, Failed to get resource with relationships when using Entity Framework Core Sqlite #918
Npgsql.PostgresException (0x80004005): 42703: column t.TagId does not exist.
PostgreSQL and SQL Server with many-to-many relationship, Nested inclusion leads to error: An unhandled error occurred while processing this request. #920
When this happens, the produced SQL usually contains an
OUTER APPLY
orLEFT JOIN LATERAL
clause.Environment
JsonApiDotNetCore: v4.x
EF Core: v3.1.x and v5
Database providers: SQL Server, SQLLocalDB, Sqlite, PostgreSQL
Background
In v4-beta1, we redesigned the generation of the LINQ expressions that we feed to EF Core. Among other things, we added paging
for non-primary endpoints (/articles/1/authors) and for includes (/articles?include=authors).
Because paging is enabled by default, this generates a LINQ expression with multiple Skip/Take clauses.
In most cases that works fine, but occasionally it causes the errors listed above.
The EF Core team is aware of this problem and recently proposed an internal design change at dotnet/efcore#17337 (comment) that's going to solve this. Aside from us, the OData team (Microsoft) reported the same problem at dotnet/efcore#19763, which contains a comment from an EF Core team member saying the underlying issue is committed to be fixed in EF Core 6.0.
If this fix is important to you, please upvote the issue so it gets prioritized.
Workarounds
.AddJsonApi(...)
from Startup.cs:Note this makes simple requests succeed, but still fails when paging at both levels is explicitly asked for:
and register it from Startup.cs, after
.AddJsonApi(...)
:Instead of registering the unconstrained generic, you can inherit and register resource-specific subclasses if you want to control this per resource type.
The text was updated successfully, but these errors were encountered: