I am currently developing an OData web service with ASP.NET Core. I have a controller for companies and added an endpoint as an OData function to retrieve subsidiaries.
The subsidiaries should be displayed in a grid (I use DevExpress controls so I cannot directly influence the calls made by the control). The grid executes a call to the /$count endpoint (via a generated Microsoft.OData.Client), but this leads to a 404 error in the OData function. Is there a way to support the /$count endpoint, either by customizing the function or by using a separate method in my controller to route to this endpoint?
Request:
Request finished HTTP/1.1 GET http://localhost:16423/api/current/Companies/GetSubsidiaries(companyId=1)/$count - - - 404
OData model:
builder.EntitySet<Company>("Companies");
var subsidiaryFunction = builder.EntityType<Company>().Collection
.Function(nameof(CompanyController.GetSubsidiaries))
.ReturnsCollectionFromEntitySet<Company>("Companies")
.Parameter<int>("companyId");
Controller:
/// <summary>
/// Retrieves subsidiaries based on the given <paramref name="companyId"/>.
/// </summary>
/// <param name="companyId">The id of the parent company.</param>
[HttpGet]
[EnableQuery]
public IQueryable<Company> GetSubsidiaries(int companyId)
{
return _companyRepository.QuerySubsidiaries(companyId);
}