OData / OData/AspNetCoreOData

Using $expand with ODataQueryOptions not working as expected

Open
#929 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Assemblies affected
Microsoft.AspNetCore.OData v 8.1.2

Describe the bug

  • When using ODataQueryOptions, navigation properties are automatically rendered in the output (they should not unless $expand is used)
  • When using ODataQueryOptions and $expand, the properties are output in PascalCase, not camelCase as expected

Sample code located in https://github.com/blueghostuk/odata-compute-issue/tree/ExpandIssue

When using the odata endpoint, $expand works as expected, for example:

  • http://localhost:5226/odata/Weathers
    • by default City is not expanded, as expected
    • properties are camelCase, as expected
  • http://localhost:5226/odata/Weathers?$expand=City
    • City is expanded, as expected
    • properties are camelCase, as expected

When using ODataQueryOptions, $expand does not work as expected, for example:

  • http://localhost:5226/weatherforecast
    • by default City is expanded, I would expect it not to be
    • properties are camelCase, as expected
{
    "id": "c04014be-1cb9-4594-8ca2-2a6a7e99aade",
    "date": "2023-05-18T10:51:08.7642677+01:00",
    "temperatureC": -20,
    "temperatureF": -3,
    "summary": "Cool",
    "cityId": "a9e24c44-f205-43d7-af3f-4890ee7754ba",
    "city": {
      "id": "a9e24c44-f205-43d7-af3f-4890ee7754ba",
      "name": "Manchester"
    }
  }
  • http://localhost:5226/weatherforecast?$expand=City
    • this expands City, but notice the properties are PascalCase, not camelCase as expected
{
    "City": {
      "Id": "c433ee91-4e95-4dd4-ae95-36a494820ec0",
      "Name": "London"
    },
    "Id": "2b5a0675-0a02-4e2d-8daf-ab786e3f0aef",
    "Date": "2023-05-18T10:51:54.2713482+01:00",
    "TemperatureC": 46,
    "TemperatureF": 114,
    "Summary": "Chilly",
    "CityId": "c433ee91-4e95-4dd4-ae95-36a494820ec0"
  }

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.

Research direction

Start with the sample project at https://github.com/blueghostuk/odata-compute-issue/tree/ExpandIssue and run the documented /odata/Weathers and /weatherforecast requests with and without $expand. Compare the OData endpoint with the ODataQueryOptions endpoint, focusing on navigation-property expansion and PascalCase versus camelCase output. Done means both endpoints follow the expected expansion and naming behavior, with the relevant behavior covered by a regression test if the repository provides a test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.