Dynamic OData Model w/ EnableQuery
@xuzhg is already working on this.
Since Jan 10, 2023.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Discussed in https://github.com/OData/AspNetCoreOData/discussions/789
Expansion for dynamic models when using the EnableQuery attribute generates a runtime exceptions like so:
The query specified in the URI is not valid. Could not find a property named 'Items' on type 'Microsoft.AspNetCore.OData.Formatter.Value.IEdmEntityObject'.
The exception only occurs when the EnableQuery attribute is present. With it removed all requests process without issue, but expansion beyond "level 2" for self-referencing navigation properties is problematic. I've stepped through the OData Lib and observed behavior within Microsoft.OData.UriParser's SelectExpandBinder class. The GenerateExpandItem method contained therein is unable to resolve properties for the dynamically generated models (IEdmEntityObject) returned from my data source.
A working solution is attached. To reproduce the issue, follow these steps:
-
Remove the EnableQuery attribute from the lone controller method and invoke the following URL:
http://localhost:4527/odata/ns/Items?$expand=Detail,Items($expand=Detail,Items($expand=Detail,Items($expand=Detail,Items))) -
Make note of the levels contained with the previous response before invoking the following URL:
http://localhost:4527/odata/ns/Items?$expand=Items($levels=10;$expand=Detail),Detail -
Note that the previous response expanded 2 levels only.
-
Add the EnableQuery attribute back to the controller method and re-invoke the prior URLs, at which time the aforementioned exception will occur.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.