protected async Task <ListModel <TResult> > RetrieveListResults <TSource, TResult>(Expression <Func <TSource, bool> > predicate, List <SortTuple <TSource> > orderFunctions, GetListBase request, CancellationToken cancellationToken) where TSource : class where TResult : class { var filteredQuery = Context.Set <TSource>().AsQueryable(); if (predicate != null) { filteredQuery = filteredQuery.Where(predicate); } var count = filteredQuery.CountAsync(); var sortedQuery = filteredQuery; if (orderFunctions != null) { sortedQuery = ApplyOrdering(filteredQuery, orderFunctions); } var pagedQuery = ApplyPaging(request, sortedQuery); return(await ProjectTo <TSource, TResult>(pagedQuery, await count, cancellationToken)); }
protected IQueryable <T> ApplyPaging <T>(GetListBase request, IQueryable <T> filteredQuery) where T : class { return(filteredQuery .Skip((request.PageIndex - 1) * request.PageSize) .Take(request.PageSize)); }