222
schangxiang@126.com
2024-11-29 dd53f4d569ed4e48bba9b0912353d54112876342
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareCommon.Utils
{
 
    /// <summary>
    /// 分页帮助类
    /// </summary>
    public class PageHelper
    {
        /// <summary>
        /// 分页
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="source"></param>
        /// <param name="PageNum">每页显示条数</param>
        /// <param name="PageIndex">第几页</param>
        /// <returns></returns>
        public static List<TEntity> Page<TEntity>(IQueryable<TEntity> source, int PageNum, int PageIndex) where TEntity : class
        {
            List<TEntity> list = new List<TEntity>();
            int count = PageNum * (PageIndex - 1);
            list = source.Skip<TEntity>(count).Take<TEntity>(PageNum).ToList<TEntity>();
            return list;
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="source"></param>
        /// <param name="PageNum">每页显示条数</param>
        /// <param name="PageIndex">第几页</param>
        /// <returns></returns>
        public static List<TEntity> Page<TEntity>(IList<TEntity> source, int PageNum, int PageIndex) where TEntity : class
        {
            List<TEntity> list = new List<TEntity>();
            int count = PageNum * (PageIndex - 1);
            list = source.Skip<TEntity>(count).Take<TEntity>(PageNum).ToList<TEntity>();
            return list;
        }
    }
}