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?
{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.ODataRoutewhen I try to add it as an attribute for my action. Maybe it was replaced or simply removed...