Reputation: 5946
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:
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?
Upvotes: 2
Views: 3768
Reputation: 5946
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();
}
Upvotes: 2