using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Utility
{
public class SqlSugarPagedList
{
///
/// 总条数
///
public int Total { get; set; }
///
/// 总页数
///
public int TotalPages { get; set; }
///
/// 当前页集合
///
public object Items { get; set; }
}
///
/// 分页拓展类
///
public static class SqlSugarPagedExtensions
{
///
/// 分页拓展
///
/// 对象
/// 当前页码,从1开始
/// 页码容量
///
public static async Task ToPagedListAsync(this ISugarQueryable query, int pageIndex, int pageSize)
where TEntity : new()
{
RefAsync total = 0;
var items = await query.ToPageListAsync(pageIndex, pageSize, total);
var totalPages = pageSize > 0 ? (int)Math.Ceiling(total / (double)pageSize) : 0;
return new SqlSugarPagedList
{
Items = items,
Total = total,
TotalPages = totalPages,
};
}
}
}