You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zongzhilinglan/Magic.Core/Extension/PagedQueryableExtensions.cs

36 lines
1.1 KiB

using SqlSugar;
using System;
using System.Threading.Tasks;
namespace Magic.Core;
/// <summary>
/// 分页拓展类
/// </summary>
public static class PagedQueryableExtensions
{
/// <summary>
/// 分页拓展
/// </summary>
/// <param name="query"></param>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
public static async Task<SqlSugarPagedList<TEntity>> ToPagedListAsync<TEntity>(this ISugarQueryable<TEntity> query, int pageIndex, int pageSize)
{
RefAsync<int> totalCount = 0;
var items = await query.ToPageListAsync(pageIndex, pageSize, totalCount);
var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
return new SqlSugarPagedList<TEntity>
{
PageIndex = pageIndex,
PageSize = pageSize,
Items = items,
TotalCount = (int)totalCount,
TotalPages = totalPages,
HasNextPages = pageIndex < totalPages,
HasPrevPages = pageIndex - 1 > 0
};
}
}