I have a problem with a PaginatedList in a Web API project.
In the repository there's a method like:
public virtual PaginatedList<T> Paginate<TKey>(int pageIndex, int pageSize,
Expression<Func<T, TKey>> keySelector,
Expression<Func<T, bool>> predicate,
params Expression<Func<T, object>>[] includeProperties)
{
IQueryable<T> query = AllIncluding(includeProperties).OrderBy(keySelector);
query = (predicate == null)
? query
: query.Where(predicate);
return query.ToPaginatedList(pageIndex, pageSize);
}
But, when I try to use it, like this:
var a = repository.Paginate<Region>(pageNo, pageSize, x => x.ID, null);
I get this error:
Cannot implicitly convert type 'int' to 'Domain.Entities.Dictionaries.Region'
What am I doing wrong?
The paginate method provided by Laravel automatically takes care of setting the proper limit and offset based on the current page being viewed by the user. By default, the current page is detected by the value of the ? page query string argument on the HTTP request.
Pagination is used in some form in almost every web application to divide returned data and display it on multiple pages within one web page. Pagination also includes the logic of preparing and displaying the links to the various pages. Pagination can be handled client-side or server-side.
1 : the action of paging : the condition of being paged. 2a : the numbers or marks used to indicate the sequence of pages (as of a book) b : the number and arrangement of pages or an indication of these.
Your method signature has TKey
that i suppose is a key for sorting, but in your call you are specifying the whole object Region
, and then you specify int
in the keySelector
, so it can't compile it as it tries to use int
type as Region
type for TKey
.
I suppose your sample should be:
repository.Paginate<int>(pageNo, pageSize, x => x.ID, null);
Generic type T
i suppose is specified for the whole class, so it should be fine here to not specify it in the call, as repository instance is already generic specific.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With