OData / OData/AspNetCoreOData

Route template parameters order cannot be changed even with ODataAttributeRoutingAttribute

Open
#683 10 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
ASP.NET Core OData 8.0.11

Describe the bug
Refering to this post from @xuzhg
https://stackoverflow.com/questions/72182707/odata-v7-8-should-composite-keys-be-in-alpha-order-or-haskey-when-key-value

Or you can use the attribute routing. In attribute routing, you can set any order in the route template.

I tried with ODataRoutingSample and it didn't work (or I didn't understand something)

Reproduce steps

  1. Open the AspNetCoreOData solution
  2. Edit ODataRoutingSample.Controllers.PeopleController to inherit from ODataController (which has a ODataAttributeRouting attribute)
  3. Launch the ODataRoutingSample project

This request works :
http://localhost:64771/People(FirstName='Magazine',LastName='Jingchan')

But this request does not work (404) :
http://localhost:64771/People(LastName='Jingchan',FirstName='Magazine')

Additional context
I think it is important to allow the key parameters to be specified in any order.
I know you can enforce it with the Order property in the model configuration, but since query parameters in MVC can be set in any order, same is expected for the key parameters from the route template.

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 by opening the AspNetCoreOData solution and the ODataRoutingSample.Controllers.PeopleController described in the reproduction steps. Run the sample and compare the two People requests with reversed key parameters, then trace the ODataAttributeRouting behavior. Done means both URL parameter orders route successfully instead of the reversed order returning 404.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.