using System.Threading.Tasks;
namespace SqlSugar;
///
/// 扩展SqlSugar SugarQueryable进行分页
///
public static class SugarQueryableExtensions
{
///
/// 分页拓展
///
///
///
///
public static PageResult ToPagedList(this ISugarQueryable queryable, IPagination input)
{
int totalCount = 0;
var items = queryable.ToPageList(input.PageNo, input.PageSize, ref totalCount);
var totalPages = (int)Math.Ceiling(totalCount / (double)input.PageSize);
return new PageResult()
{
PageNo = input.PageNo,
PageSize = input.PageSize,
Rows = items,
Total = totalCount,
Pages = totalPages,
};
}
///
/// 分页拓展
///
///
///
///
public static async Task> ToPagedListAsync(this ISugarQueryable queryable, IPagination input)
{
RefAsync totalCount = 0;
var items = await queryable.ToPageListAsync(input.PageNo, input.PageSize, totalCount);
var totalPages = (int)Math.Ceiling(totalCount / (double)input.PageSize);
return new PageResult()
{
PageNo = input.PageNo,
PageSize = input.PageSize,
Rows = items,
Total = (int)totalCount,
Pages = totalPages,
};
}
}