2

I made my first OData-Request work:

[HttpGet]
[EnableQuery]
public IQueryable<ApplicationUser> Get()
{
    return _applicationUserRepository.GetAll();
}

now I wanted to add the second one for Get(id):

[HttpGet]
[EnableQuery]
public ApplicationUser Get([FromODataUri]long id)
{
    return _applicationUserRepository.Get(id).Result;
}

Problem now is, when I try to execute the first call with postman, the result is: GET http://localhost:5000/api/v1/applicationuser?$filter=startsWith(LastName,%20%27Test%27)

Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:

  • MyAssambly.Controllers.ApplicationUserController.Get (MyAssambly)
  • MyAssambly.Controllers.ApplicationUserController.Get (MyAssambly)

at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateState[] candidateState) at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, CandidateState[] candidateState) at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, CandidateState[] candidateState) at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.SelectAsync(HttpContext httpContext, CandidateSet candidateSet) at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask) at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

So I don't have any idea what the problem could be. The methods are different and the second one should definitively call that with the ID parameter. What am I doing wrong?

2
  • I haven't worked with OData before, but I can imagine that you would need to define {id} as part of the route, or use a OData attribute if it has route attributes. Looking on the internet I found [ODataRoute("({Id})")] that someone has put on their method to differentiate routes between the GET and GET with the (id). And, this is how it works with REST APIs to, so most likely that's your problem. Commented Apr 9, 2021 at 22:25
  • @Dennis1679 exactly my thoughts, and I also tried this. But in v8.0.0-rc it cannot resolve the Symbol ODataRoute when I try to add it as an attribute for my action. Maybe it was replaced or simply removed... Commented Apr 10, 2021 at 6:34

1 Answer 1

2

The problem is, that we need to use something like the ORouteData-Attribute. But in Version 8.0.0-rc this attribute is gone.

Documentation says, we need to use the Http verb attributes:

[EnableQuery]
[HttpGet("ApplicationUser")]
[HttpGet("ApplicationUser/$count")]
public IQueryable<ApplicationUser> Get()
{
    return _applicationUserRepository.GetAll();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.