/// <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="pageIndex">0-based page index</param>
        /// <param name="pageSize"></param>
        /// <param name="descending"></param>
        /// <param name="whereExpression"></param>
        /// <param name="orderExpression"></param>
        /// <param name="countTotal"></param>
        /// <returns></returns>
        public virtual async Task <RepositoryResult <TEntity> > FindPageAsync <TEntity, TOrder>(int pageIndex, int pageSize, bool descending
                                                                                                , Expression <Func <TEntity, bool> > whereExpression, Expression <Func <TEntity, TOrder> > orderExpression
                                                                                                , bool countTotal)
            where TEntity : class
        {
            var result = new RepositoryResult <TEntity>();

            Task <List <TEntity> > listQuery = FindPageQuery(pageIndex, pageSize
                                                             , descending, whereExpression, orderExpression)
                                               .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="pageIndex">0-based page index</param>
        /// <param name="pageSize"></param>
        /// <param name="descending"></param>
        /// <param name="whereExpression"></param>
        /// <param name="orderExpression"></param>
        /// <param name="countTotal"></param>
        /// <returns>If page number starts from 0, otherwise from 1.</returns>
        public virtual RepositoryResult <TEntity> FindPage <TEntity, TOrder>(int pageIndex, int pageSize, bool descending
                                                                             , Expression <Func <TEntity, bool> > whereExpression, Expression <Func <TEntity, TOrder> > orderExpression
                                                                             , bool countTotal)
            where TEntity : class
        {
            var result = new RepositoryResult <TEntity>();

            result.Data = FindPageQuery(pageIndex, pageSize
                                        , descending, whereExpression, orderExpression)
                          .ToList();

            if (countTotal)
            {
                result.TotalRows = Context.Set <TEntity>()
                                   .Where(whereExpression)
                                   .LongCount();
            }

            return(result);
        }