OData / OData/AspNetCoreOData

Duplicate results shown in OData route debug view for conventional and attribute routed routes

Open
#428 3 comments 3 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Jan 12, 2022.

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

Description

  • Latest affected version: Microsoft.AspNetCore.OData v8.0.5

The OData route debug view currently show matches for all conventions, regardless if they are duplicates. Let's take the default Weather Forecast sample for this.

If we have:

[Route("Forecasts")]
public class ForecastsController : ODataController
{
    [HttpGet]
    public IQueryable<WeatherForecast> Whatever()
    {
        return this.repository.GetForecasts();
    }

Then the debug view correctly lists GET Forecasts only once:
image

However, if I change the method name from Whatever to Get, it will now show the exact same route twice (due to now matching both via convention, and attribute routing):

[Route("Forecasts")]
public class ForecastsController : ODataController
{
    [HttpGet]
    public IQueryable<WeatherForecast> Get()
    {
        return this.repository.GetForecasts();
    }

image

The application works correctly in both cases, resolving the GET action to the same method. The way the routes are displayed in the debug view, however, is fairly confusing. IMHO, this should be fixed in one of 2 ways:

  1. Remove duplicate entries from the table and only show the first matches for each route (like what the convention priority itself does normally, which will hit the attribute route and skip other conventions)
  2. Add a third column to the table, to indicate which convention resulted in the route's inclusion.

1 seems simpler to me, but 2 might be of help for debugging purposes.

FYI, the exact same behavior is present for all other route types and verbs: as long as they are attribute routed and match the naming convention at the same time, they appear twice. I used the GET entityset here as an example only.

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.