2
I’ve worked on some frameworks like Spring and Nestjs, and there I worked with a library that listed a query page.
Here at . Net Core, I have to create a method to work with it. For example:
public PagedSearchDTO<PersonVO> FindWithPagedSearch(string name, string sortDirection, int pageSize, int page)
{
page = page > 0 ? page - 1 : 0;
string query = @"select * from persons p where 1 = 1 ";
if (!string.IsNullOrEmpty(name)) query = query + $"and p.firstname like '%{name}%' ";
query = query + $" order by p.firstname {sortDirection} limit {pageSize} offset {page}";
string countQuery = @"select count(*) from persons p where 1 = 1 ";
if (!string.IsNullOrEmpty(name)) countQuery = countQuery + $" and p.name like '%{name}%' ";
var persons = _repository.FindWithPagedSearch(query);
int totalResults = _repository.GetCount(countQuery);
return new PagedSearchDTO<PersonVO>
{
CurrentPage = page + 1,
List = _converter.ParseList(persons),
PageSize = pageSize,
SortDirections = sortDirection,
TotalResults = totalResults
};
}
I would like to know if there is already a library, preferably official language, that works with this paging logic?
The documentation you put in is great, but it would be even better if you put a practical example in the answer. :)
– George Wurthmann
George I did not put in the answer the example because the tutorial on paging has the full example. It would just repeat what is already there.
– Fabri Damazio