public static PagingResult <TItem> ApplyPaging <TKey, TItem>(
            this IQueryable <ICacheEntry <TKey, TItem> > queryable,
            PagingParameters pagingParameters)
        {
            var totalCount = queryable.Count();

            var items = queryable.Skip(pagingParameters.Offset).Take(pagingParameters.Limit).Select(c => c.Value);

            return(PagingResult.Create(items.ToList(), pagingParameters.Offset, totalCount));
        }
Esempio n. 2
0
        public async Task <PagingResult <TEntity> > GetListAsync(int start, int length, Expression <Func <TEntity, bool> > predicate,
                                                                 string[] includes)
        {
            IQueryable <TEntity> query = _context.Set <TEntity>();

            query = query.AsNoTracking();
            foreach (var inc in includes)
            {
                query = query.Include(inc);
            }
            var allCount = await query.CountAsync();

            if (predicate != null)
            {
                query = query.Where(predicate);
            }
            query = query.Skip(start).Take(length);
            var filteredCount = await query.CountAsync();

            var result = await query.ToListAsync();

            return(PagingResult <TEntity> .Create(result, allCount, filteredCount));
        }