示例#1
0
        /// <summary>
        /// 获取分页数据(仅获取列表,不获取总数量)
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="source">数据源</param>
        /// <param name="pageInput">分页参数</param>
        /// <returns></returns>
        public static List <T> GetPageList <T>(this IQueryable <T> source, PageInput pageInput)
        {
            var list = source.OrderBy($@"{pageInput.SortField} {pageInput.SortType}")
                       .Skip((pageInput.PageIndex - 1) * pageInput.PageRows)
                       .Take(pageInput.PageRows)
                       .ToList();

            return(list);
        }
        /// <summary>
        /// 获取分页数据(仅获取列表,不获取总数量)
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="iEnumberable">数据源</param>
        /// <param name="pageInput">分页参数</param>
        /// <returns></returns>
        public static List <T> GetPageList <T>(this IEnumerable <T> iEnumberable, PageInput pageInput)
        {
            var list = iEnumberable.AsQueryable()
                       .OrderBy($@"{pageInput.SortField} {pageInput.SortType}")
                       .Skip((pageInput.PageIndex - 1) * pageInput.PageRows)
                       .Take(pageInput.PageRows)
                       .ToList();

            return(list);
        }
示例#3
0
        /// <summary>
        /// 获取分页数据(包括总数量)
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="source">数据源</param>
        /// <param name="pageInput">分页参数</param>
        /// <returns></returns>
        public static PageResult <T> GetPageResult <T>(this IQueryable <T> source, PageInput pageInput)
        {
            int count = source.Count();

            var list = source.OrderBy($@"{pageInput.SortField} {pageInput.SortType}")
                       .Skip((pageInput.PageIndex - 1) * pageInput.PageRows)
                       .Take(pageInput.PageRows)
                       .ToList();

            return(new PageResult <T> {
                Data = list, Total = count
            });
        }
        /// <summary>
        /// 获取分页数据(包括总数量)
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="iEnumberable">数据源</param>
        /// <param name="pageInput">分页参数</param>
        /// <returns></returns>
        public static PageResult <T> GetPageResult <T>(this IEnumerable <T> iEnumberable, PageInput pageInput)
        {
            int count = iEnumberable.Count();

            var list = iEnumberable.AsQueryable()
                       .OrderBy($@"{pageInput.SortField} {pageInput.SortType}")
                       .Skip((pageInput.PageIndex - 1) * pageInput.PageRows)
                       .Take(pageInput.PageRows)
                       .ToList();

            return(new PageResult <T> {
                data = list, total = count, current = pageInput.PageIndex, pageSize = pageInput.PageRows
            });
        }
示例#5
0
        /// <summary>
        /// 获取分页数据(包括总数量)
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="source">数据源</param>
        /// <param name="pageInput">分页参数</param>
        /// <returns></returns>
        public static async Task <PageResult <T> > GetPageResultAsync <T>(this IQueryable <T> source, PageInput pageInput)
        {
            int count = await source.CountAsync();

            var list = await source.OrderBy($@"{pageInput.SortField} {pageInput.SortType}")
                       .Skip((pageInput.PageIndex - 1) * pageInput.PageRows)
                       .Take(pageInput.PageRows)
                       .ToListAsync();

            return(new PageResult <T> {
                data = list, total = count, current = pageInput.PageIndex, pageSize = pageInput.PageRows
            });
        }