12345678910111213141516171819202122232425262728293031323334 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bowin.Common
- {
- public class PageList<T>
- {
- /// <summary>
- /// 构造函数,当 pageIndex 或 pageSize 为null时,获取全部数据。
- /// </summary>
- /// <param name="query"></param>
- /// <param name="pageIndex">页码,从1开始</param>
- /// <param name="pageSize">页数</param>
- public PageList(IQueryable<T> query, int? pageIndex, int? pageSize)
- {
- if (pageSize.HasValue && pageIndex.HasValue)
- {
- Total = query.Count();
- Items = query.Skip((pageIndex.Value - 1) * pageSize.Value).Take(pageSize.Value);
- }
- else
- {
- Total = query.Count();
- Items = query;
- }
- }
- public int Total { get; private set; }
- public IQueryable<T> Items { get; private set; }
- }
- }
|