public async Task <PagedList <TEntity> > ToPagedListAsync(IQueryable <TEntity> query, PageOptions pageOptions, CancellationToken cancellationToken = default) { pageOptions = ResolvePageOptions(pageOptions); var result = await query .Skip(pageOptions.GetOffset().Value) .Take(pageOptions.GetLimit().Value) .ToListAsync(cancellationToken); return(new PagedList <TEntity>() { Items = result, Count = await query.CountAsync(cancellationToken) }); }
public async Task <PagedList <TEntity> > GetPagedAllAsync(PageOptions pageOptions, Expression <Func <TEntity, bool> > predicate = null, CancellationToken cancellationToken = default) { pageOptions = ResolvePageOptions(pageOptions); var query = _set.AsQueryable(); if (predicate != null) { query = query.Where(predicate); } var result = await query .Skip(pageOptions.GetOffset().Value) .Take(pageOptions.GetLimit().Value) .ToListAsync(cancellationToken); return(new PagedList <TEntity>() { Items = result, Count = await query.CountAsync(cancellationToken) }); }