PagedQueryableExtensions.cs
1.92 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Threading.Tasks;
namespace SqlSugar
{
/// <summary>
/// 分页拓展类
/// </summary>
public static class PagedQueryableExtensions
{
/// <summary>
/// 分页拓展
/// </summary>
/// <param name="entity"></param>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
public static SqlSugarPagedList<TEntity> ToPagedList<TEntity>(this ISugarQueryable<TEntity> entity, int pageIndex, int pageSize)
where TEntity : new()
{
var totalCount = 0;
var items = entity.ToPageList(pageIndex, pageSize, ref totalCount);
var pagination = new PagedModel() {
PageIndex = pageIndex,
PageSize = pageSize,
Total = (int)totalCount
};
return new SqlSugarPagedList<TEntity>
{
pagination = pagination,
list = items
};
}
/// <summary>
/// 分页拓展
/// </summary>
/// <param name="entity"></param>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
public static async Task<SqlSugarPagedList<TEntity>> ToPagedListAsync<TEntity>(this ISugarQueryable<TEntity> entity, int pageIndex, int pageSize)
where TEntity : new()
{
RefAsync<int> totalCount = 0;
var items = await entity.ToPageListAsync(pageIndex, pageSize, totalCount);
var pagination = new PagedModel()
{
PageIndex = pageIndex,
PageSize = pageSize,
Total = (int)totalCount
};
return new SqlSugarPagedList<TEntity>
{
pagination = pagination,
list = items
};
}
}
}