PagedQueryableExtension.cs 901 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace gpt_api.Core.Extensions
  7. {
  8. /// <summary>
  9. /// 分页扩展
  10. /// </summary>
  11. public static class PagedQueryableExtension
  12. {
  13. /// <summary>
  14. /// 获取分页列表
  15. /// </summary>
  16. /// <param name="query"></param>
  17. /// <param name="page"></param>
  18. /// <returns></returns>
  19. public static async Task<PagedList<TEntity>> ToPagedListAsync<TEntity>(this ISugarQueryable<TEntity> query, PagedInput page)
  20. {
  21. RefAsync<int> count = 0;
  22. List<TEntity> result = await query.ToPageListAsync(page.PageIndex, page.PageSize, count);
  23. return new PagedList<TEntity>
  24. {
  25. TotalCount = count.Value,
  26. List = result
  27. };
  28. }
  29. }
  30. }