I'm using OData in my asp.net core3.1 app and what to delegate the pagination to the client. I'm stuck at how to return alog with the given number of entries, the total number of entries in a table. For example having a table with 100 entries, I want to be able to get this information to know exactly how to create my page component.
Service registration
services.AddOData();
Configuration
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.EnableDependencyInjection();
endpoints.Expand().Select().Count().Filter().OrderBy().SkipToken().MaxTop(20);
});
This is the endpoint
[HttpGet]
[EnableQuery]
[Produces("application/json")]
public IActionResult Get()
{
var query = dbContext.Users;
return Ok(query);
}
I'm using this query -
https://localhost:1234/api/users?$count=true&$select=id,name,version&$skip=0&$top=5
outputs just a list of 5 objects, no extra metadata.
[
{
Id: "1",
Name: "a",
Version: "1"
},
... 4 more objects
]