I want to create a generic repository, and have a method that returns an IPagedList like the following:
public IPagedList<TEntity> GetPage(int? page, int? size)
{
IQueryable<TEntity> query = _dbSet; // DbSet<TEntity> _dbSet;
return query.ToPagedList(page ?? 1, size ?? 10);
}
However, IPagedList requires to add an OrderBy() or it throws the following message:
The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
How can i achieve this, how can i add ordering for TEntity type? I can have the method return IQueryable and do the paging on controller / caller and it works, but wanted to do this on the generic repository.