/// <summary> /// Select a page of row, optionally getting total count of rows matching Where criteria. /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TOrder"></typeparam> /// <param name="page"></param> /// <param name="pageSize"></param> /// <param name="descending"></param> /// <param name="whereExpression"></param> /// <param name="orderExpression"></param> /// <param name="countTotal"></param> /// <param name="pageIsZeroBased">If page number starts from 0, otherwise from 1.</param> /// <returns></returns> public virtual async Task <RepositoryResult <TEntity> > SelectPageAsync <TEntity, TOrder>(int page, int pageSize, bool descending , Expression <Func <TEntity, bool> > whereExpression, Expression <Func <TEntity, TOrder> > orderExpression , bool countTotal, bool pageIsZeroBased) where TEntity : class { var result = new RepositoryResult <TEntity>(); Task <List <TEntity> > listQuery = SelectPageQuery(page, pageSize , descending, whereExpression, orderExpression, pageIsZeroBased) .ToListAsync(); Task <long> countQuery = null; if (countTotal) { countQuery = Context.Set <TEntity>() .Where(whereExpression) .LongCountAsync(); } result.Data = await listQuery.ConfigureAwait(false); if (countTotal) { result.TotalRows = await countQuery.ConfigureAwait(false); } return(result); }
/// <summary> /// Select a page of row, optionally getting total count of rows matching Where criteria. /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TOrder"></typeparam> /// <param name="page"></param> /// <param name="pageSize"></param> /// <param name="descending"></param> /// <param name="whereExpression"></param> /// <param name="orderExpression"></param> /// <param name="countTotal"></param> /// <param name="pageIsZeroBased"></param> /// <returns>If page number starts from 0, otherwise from 1.</returns> public virtual RepositoryResult <TEntity> SelectPage <TEntity, TOrder>(int page, int pageSize, bool descending , Expression <Func <TEntity, bool> > whereExpression, Expression <Func <TEntity, TOrder> > orderExpression , bool countTotal, bool pageIsZeroBased) where TEntity : class { var result = new RepositoryResult <TEntity>(); result.Data = SelectPageQuery(page, pageSize , descending, whereExpression, orderExpression, pageIsZeroBased) .ToList(); if (countTotal) { result.TotalRows = Context.Set <TEntity>() .Where(whereExpression) .LongCount(); } return(result); }