Ejemplo n.º 1
0
        /// <summary>
        /// IQueryable 查询结果 转 IPagedList列表 - 通常用于数据库查询转换操作
        /// </summary>
        /// <typeparam name="TEntity">领域实体 类型</typeparam>
        /// <param name="source">IQueryable查询对象</param>
        /// <param name="page">当前页</param>
        /// <param name="pageSize">页容量大小</param>
        /// <returns>IPagedList列表结果集</returns>
        public static IPagedList <TEntity> ToPagedList <TEntity>(this IQueryable <TEntity> source, int page, int pageSize) where TEntity : class, new()
        {
            long total = source.Count();
            PagedListResult <TEntity> result = new PagedListResult <TEntity>(page, pageSize, total);

            result.AddRange(source.Skip((page - 1) * pageSize).Take(pageSize));
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// IPagedList列表结果 entity 转 model
        /// </summary>
        /// <typeparam name="TEntity">领域实体 类型</typeparam>
        /// <typeparam name="TModel">业务实体 类型</typeparam>
        /// <param name="source">entity集合 对象</param>
        /// <param name="list">model集合 对象</param>
        /// <returns>IPagedList列表Model结果集</returns>
        public static IPagedList <TModel> ToPagedList <TEntity, TModel>(this IPagedList <TEntity> source, IList <TModel> list)
            where TEntity : class, new()
            where TModel : class, new()
        {
            PagedListResult <TModel> result = new PagedListResult <TModel>(source.Pager.Page, source.Pager.PageSize, source.Pager.Total);

            result.AddRange(list);

            return(result);
        }
Ejemplo n.º 3
0
        public EfPagedList(IQueryable <T> queryable, int page, int pageSize)
        {
            if (page < 1)
            {
                page = 1;
            }
            if (pageSize < 10)
            {
                pageSize = 10;
            }
            int total = queryable.Count();

            _pageResultList = new PagedListResult <T>(page, pageSize, total);
            _pageResultList.AddRange(queryable.Skip((page - 1) * pageSize).Take(pageSize));
        }