I've created a dynamic paging model to present data in pages for my projects.
In my controller I have two calls for the DB :
public async Task<IActionResult> Index(int? page)
{
...
var count = await _context.Agent.CountAsync();
var items = await _context.Agent.Skip((_page - 1) * pageSize).Take(pageSize).ToListAsync();
...
The paging works fine. I was just wondering if that's the best way in terms of performances.
As you can see, I'm making two calls to the DB, one for count to know the amount of pages, and one to get the actual data.
I don't know enough about this DB calls to know if they're being processed in the DB it self, or in the server side. If both are being processed in the DB, then everything is fine as we're saving resources , but if they're being processed on the server, I think it's better to use one call and store it in a DbSet , and manipulate the object.
So, what's better?