zoukankan      html  css  js  c++  java
  • 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;
            }

  • 相关阅读:
    洛咕 P4131 [WC2005]友好的生物
    P3354 [IOI2005]Riv 河流
    洛咕 P3645 [APIO2015]雅加达的摩天楼
    洛咕 P4528 [CTSC2008]图腾
    CSDN不登录阅读全文(最新更新
    #6472. 「ICPC World Finals 2017」难以置信的任务 Mission Improbable
    #6435. 「PKUSC2018」星际穿越
    #2009. 「SCOI2015」小凸玩密室
    #2007. 「SCOI2015」国旗计划
    PKUWC2018题解
  • 原文地址:https://www.cnblogs.com/RainbowInTheSky/p/4590508.html
Copyright © 2011-2022 走看看