Esempio n. 1
0
        public virtual async Task <PagedCollection <TGetItem> > GetPagedListAsync(PaginationFilterParams filterParams, CancellationToken ct = default)
        {
            Logger.LogInformation($"Get {typeof(TEntity).Name} paged list with parameters {filterParams.ToJsonString()}");

            PagedCollection <TEntity> dbEntities = await EntityRepository.GetPagedListAsync(filterParams, ct);

            IImmutableList <TGetItem> itemsDto = Mapper.Map <ICollection <TGetItem> >(dbEntities.Items).ToImmutableList();

            return(new PagedCollection <TGetItem>(itemsDto, dbEntities.TotalCount));
        }
        public virtual async Task <PagedCollection <TEntity> > GetPagedListAsync(PaginationFilterParams filterParams, CancellationToken ct)
        {
            var query = DbSet.AsNoTracking().AsQueryable();

            int totalCount = await query.CountAsync(ct);

            var items = await query
                        .Skip(filterParams.PageSize *(filterParams.PageNumber - 1))
                        .Take(filterParams.PageSize)
                        .AsNoTracking()
                        .ToListAsync(ct);

            return(new PagedCollection <TEntity>(items.ToImmutableList(), totalCount));
        }
        protected virtual IQueryable <TEntity> GetPagedQuery(IQueryable <TEntity> query, PaginationFilterParams filterParams, out int totalCount)
        {
            totalCount = query.Count();

            var items = query
                        .Skip(filterParams.PageSize * (filterParams.PageNumber - 1))
                        .Take(filterParams.PageSize);

            return(items);
        }