public PagedSearchDTO <Aluno> FindWithPagedSearch(string name, string sortDirection, int pageSize, int page) { page = page > 0 ? page - 1 : 0; string query = @"select * from Alunos 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 Alunos p where 1 = 1 "; if (!string.IsNullOrEmpty(name)) { countQuery = countQuery + $" and p.firstName like '%{name}%'"; } var pessoas = _repository.FindWithPagedSearch(query); int totalResults = _repository.GetCount(countQuery); return(new PagedSearchDTO <Aluno> { CurrentPage = page + 1, List = _mapper.Map <List <Aluno>, List <Aluno> >(pessoas), PageSize = pageSize, SortDirections = sortDirection, TotalResults = totalResults }); }