-
Notifications
You must be signed in to change notification settings - Fork 473
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
Querying OData entityset with expanding collection property generates SqliteException #2369
Comments
@AliAlmutawakel It's probably a problem of EF rather than ODataWebApi. Upgrade to ef core 5 and use AsSplitQuery() may help. |
The EF query is generated by ODataWebApi. I'm returning IQueryable instance inside a [EnableQuery] method. Expanding navigational properties happen in ODataWebApi code. [HttpGet]
[EnableQuery(PageSize = 20)]
[ODataRoute("Customers({keyCustomerId})/BagItems")]
public IQueryable<BagItem> GetBagItems([FromODataUri] string keyCustomerId)
=> _db.BagItems.Where(bagItem => bagItem.CustomerId.Equals(keyCustomerId)); Is there another way ODataWebApi expand navigational properties without generating an unsupported SQL command? |
@AliAlmutawakel I'm not sure. But I think the answer is no. The sql query is not created by odata webapi, it is generated by ef. OData webapi only generate expression tree. Then ef use the expression tree to generate sql query. In fact, OData webapi does not care what kind of data source and orm tool you use. Do you have a try with ef core 5 and AsSplitQuery()? Or you can downgrade to ef core 2. x if you don't want to upgrade. |
Is there a possibility that OData WebAPI generates an expression tree that doesn't compile down to an 'outer apply' command? |
I get a similar issue. I try ef core 5 with AsSplitQuery() still get the exception |
@qazq @AliAlmutawakel I raise #2380 for it. |
A valid OData WebAPI query generates an invalid SQLite command that has a syntax error. I'm using EFCore SQLite with Odata.
Assemblies affected
TargetFramework - netcoreapp3.1
SDK - Microsoft.NET.Sdk.Web
Microsoft.AspNetCore.OData - v7.5.2
Microsoft.EntityFrameworkCore.Sqlite - v3.1.10
Reproduce steps
URL:
https://localhost:5001/OData/Customers('1AA1049')/BagItems?$expand=Item($expand=UnitOfMeasure,Prices($filter=PriceListCode eq 'MAIN'))
Expected result
No SqliteException
Actual result
SQL command with invalid syntax.
Update - 1
https://localhost:5001/OData/Customers('1AA1049')/BagItems?$expand=Item($expand=UnitOfMeasure)
workshttps://localhost:5001/OData/Customers('1AA1049')/BagItems?$expand=Item($expand=Prices)
same error aboveSummary:
Get - BagItem
Expand - Item (Object)
Then Expand -- Prices (IEnumerable) *Error
Update - 2
/Items?$expand=Barcodes
same error above/Items?$expand=Prices
same error aboveIt looks like it only happens when querying an EntitySet and expanding a collection property in the EntitySet
Update - 3
Related issues:
dotnet/efcore#17230
dotnet/efcore#19178
My conclusion: Joining two tables by using expand yields an expression that compiles into an SQL statement that uses outer apply to join or to sub-query and errors because outer apply is not supported in SQLite.
The text was updated successfully, but these errors were encountered: