I inherited a project, and asked to implemented Paging across all our Repositories (500+ methods), to show only segments of data on web front end.
Current Repository is below as following. They return Task Lists, IEnumerables etc .
How would we go through, and implement paging for the following Repositories examples?
If I implement following Paged List answer, the repos return IList, not IQueryable. So the answer, would still Retrieve All the Data first (causing performance issue), and then filter it.
https://stackoverflow.com/a/5036023/12425844
Repository:
public Task<List<Product>> GetProductListByProductNumber(int bkProductNumber)
{
var productData = _context.Product
.Include(c => c.LkProducttype)
.Where(c => c.BkProductnumber == bkProductNumber).ToListAsync();
return productData ;
}
public Task<List<Product>> GetProductListByProductDescription(string productDescription)
{
var productData = _context.Product
.Include(c => c.LkProducttype)
.Where(c => c.ProductDescription == productDescription).ToListAsync();
return productData;
}
Page List Answer
public PagedList<T> Find(Expression<Func<T,bool>> predicate, int pageNumber, pageSize)
{
return repository
.Find()
.Where(predicate)
.ToPagedList(pageNumber, pageSize);
}
*Looking for an efficient way, so don't have to Recopy and Paste All the 500+ methods with paging,if possible
If changing all the Repos methods to IQueryable, that may fix the issue. However, was reading Repos should Not return IQueryable per article here Entity Framework Repository Pattern why not return Iqueryable?