linq分页扩展
直接上代碼了
public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, int>> keySelector){var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();return itemList;}public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, bool>> keySelector){var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();return itemList;}public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, string>> keySelector){var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();return itemList;}public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, DateTime>> keySelector){var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();return itemList;}public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T,int>> keySelector){var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();return itemList;}public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, bool>> keySelector){var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();return itemList;}public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, string>> keySelector){var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();return itemList;}public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, DateTime>> keySelector){var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();return itemList;}轉(zhuǎn)載于:https://www.cnblogs.com/RainbowInTheSky/p/4590508.html
總結(jié)
- 上一篇: 11,12章问题
- 下一篇: Socket编程实现简易聊天室