OData / OData/AspNetCoreOData

Dynamic OData Model w/ EnableQuery

Open
#793 10 comments 0 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Jan 10, 2023.

bug P2
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:

  1. 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)))

  2. 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

  3. Note that the previous response expanded 2 levels only.

  4. Add the EnableQuery attribute back to the controller method and re-invoke the prior URLs, at which time the aforementioned exception will occur.

ODataDynamicModel.zip

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.