public class PageListDto<T> { public int Count { get; set; } public List<T> Data { get; set; } }
public static PageListDto<T> GetPageList<T, S>(this IQueryable<T> source, int pageIndex, int pageSize, Expression<Func<T, S>> orderBy, bool isDESC = false) { Type type = typeof(T); PageListDto<T> result = new PageListDto<T>(); result.Count = source.Count(); if (isDESC) { result.Data = source.OrderByDescending(orderBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); } else { result.Data = source.OrderBy(orderBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); } return result; }
var dwadw = db.Z_TagInfo.Where(p => p.Id > 1) .GetPageList(1, 10, p => p.Status);
时间: 2024-10-24 23:34:10