Skip to content
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

[feature/netcore] Nested $expand not working #1205

Closed
techniq opened this issue Jan 11, 2018 · 7 comments
Closed

[feature/netcore] Nested $expand not working #1205

techniq opened this issue Jan 11, 2018 · 7 comments

Comments

@techniq
Copy link

techniq commented Jan 11, 2018

When attempting to expand more than 1 level deep the property is added to the model but set to null. I also do not see any mention of it in the EFCore sql query. Other operators seem to work (at least $select)

Assemblies affected

  • 7.0.0-Nightly201801081323

Reproduce steps

Attempt to expand more than 1 level deep. For example:

  • http://localhost:5000/odata/Employees?$expand=Supervisor($expand=Position)

Expected result

{
  "@odata.context": "http://localhost:5000/odata/$metadata#Employees",
  "value": [
    {
      ...
      "Supervisor": {
        ...
        "Position": { ... } // Populated with Position properties
      }
    },
    ...
  ]
}

Actual result

{
  "@odata.context": "http://localhost:5000/odata/$metadata#Employees",
  "value": [
    {
      ...
      "Supervisor": {
        ...
        "Position": null
      }
    },
    ...
  ]
}

Additional detail

I've attempted to set [EnableQuery(MaxExpansionDepth = 3)] on the endpoint but resulted in no change.

@robward-ms robward-ms self-assigned this Jan 18, 2018
@robward-ms
Copy link
Contributor

@techniq - Can you provide the code that builds the model?

@robward-ms
Copy link
Contributor

@techniq - Can you provide the code that builds the model?

@techniq
Copy link
Author

techniq commented Feb 27, 2018

@robward-ms Actually, I think I have more details that can help (after some more testing).

Currently, this still returns the null Position as indicated above:

[EnableQuery()]
public IQueryable<Employee> Get()
{
    return DbContext.Employees;
}

but using the following fixes this problem

[HttpGet]
public IActionResult Get(ODataQueryOptions<Employee> queryOptions)
{
    var querySettings = new ODataQuerySettings()
    {
        // Workaround for: https://github.com/aspnet/EntityFrameworkCore/issues/10721
        HandleNullPropagation = HandleNullPropagationOption.False
    };

    var query = queryOptions.ApplyTo(DbContext.Set<Employee>(), querySettings);
    return Ok(query);
}

Removing HandleNullPropagation = HandleNullPropagationOption.False shows the same issues as [EnableQuery], but adding it fixes this issue (and dotnet/efcore/issues/10721). I also thought it fixed dotnet/efcore#10721, but after more testing, that looks to be fixed even using [EnableQuery()] now (I'm using 7.0.0-Nightly201802211312)

@robward-ms
Copy link
Contributor

@techniq - On EFCore?

There is some code missing to set NullPropgation for EFCore, I have it in the EFCore investigation branch: https://github.com/robward-ms/WebApi/blob/0ba1ddca056555a1aef556e6493c57b29dcef2ed/src/Microsoft.AspNet.OData.Shared/Query/HandleNullPropagationOptionHelper.cs

@techniq
Copy link
Author

techniq commented Feb 27, 2018

@robward-ms yes, 2.0.1

@techniq
Copy link
Author

techniq commented Mar 2, 2018

Resolved, thanks @robward-ms

@techniq techniq closed this as completed Mar 2, 2018
@urko-b
Copy link

urko-b commented Apr 16, 2018

Does anyone knows why I have to explicitly add NavigationParameters when I try to query my API with $Expand. In Framework 4.6 API with OData V4 I only had to add the reserved word "Virtual" to each navigation property.

Those images are from my AspNetCore.OData API
image
image
image

Here, with postman I try to get the user information with it's navigation property
image

Here is the result if i do not explicitly add the navigation property names in the controller method:
image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants