public virtual async Task <IPagedList <TAggregateRoot> > GetAsync(ISpecification <TAggregateRoot> specification, ISorter <TAggregateRoot> sorter = null, IPagedInfo pagedInfo = null) { var q = Queryable().AsNoTracking() .SafeApply(specification) .SafeSort(sorter ?? new DefaultSorter()) .SafeApply(pagedInfo); var result = await q.ToListAsync(); return(new PagedList <TAggregateRoot>(result, pagedInfo?.Page ?? 1, pagedInfo?.PageSize ?? result.Count, result.Count)); }
public static IQueryable <T> SafeApply <T>(this IQueryable <T> query, IPagedInfo pagedInfo) => pagedInfo?.PageSize == null ? query : query.Skip(pagedInfo.Page * pagedInfo.PageSize.Value).Take(pagedInfo.PageSize.Value);
public Task <IPagedList <T> > GetAsync(ISpecification <T> specification, ISorter <T> sorter = null, IPagedInfo pagedInfo = null) => _read.GetAsync(specification, sorter, pagedInfo);