using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections; /// <summary>
/// Page helper, default page size = 10
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="entity"></typeparam>
public class LinqPageHelper<T, entity> where T : IEnumerable<entity>
{
T _collection;
int _pageCount;
int _pageSize;
public static readonly int defaultPageSize = ; /// <summary>
/// Capacity of a single page
/// </summary>
public int PageSize
{
get { return _pageSize; }
set
{
_pageSize = value;
onPageSizeChanged();
}
} /// <summary>
/// Total page count
/// </summary>
public int PageCount
{
get
{
return _pageCount;
}
set
{
_pageCount = value;
}
} /// <summary>
/// Total count
/// </summary>
public int Count
{
get { return _collection.Count(); }
} private LinqPageHelper()
{
} public LinqPageHelper(T t)
: this(t, defaultPageSize)
{ } public LinqPageHelper(T t, int pageSize)
{
_collection = t;
_pageSize = pageSize;
onPageSizeChanged();
} private void onPageSizeChanged()
{
_pageCount = (_collection.Count() - + _pageSize) / _pageSize;
} public IEnumerable<entity> Take(int currentPage)
{
if (currentPage <= || currentPage > PageCount)
{
return null;
} var query =
_collection.Take(_pageSize * currentPage).Skip(_pageSize * (currentPage - ));
return query;
} public bool IsLastPage(int currentPage)
{
return currentPage == _pageCount;
}
}

eg.

            LinqPageHelper<IEnumerable<DataEntity>, DataEntity> helper =
new LinqPageHelper<IEnumerable<DataEntity>, DataEntity>(list);
helper.PageSize = pageSize;
var result = helper.Take(currentPage);

LINQ分页工具的更多相关文章

  1. c#分页工具类,完美实现List分页

    using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Proje ...

  2. Linq学习工具及Lamada表达式

    好东西.转载一个.以备学习 Linq学习工具:     http://www.linqpad.net/ Lamada表达式: Func<int, int, int> IntPow = (x ...

  3. Linq 分页不可缺少的两个方法

    //LINQ分页的方法 //1.获取总页数 public int GetPageCount(int pageSize)//pageSize是每页的行数 { //先查出总共有多少行 int rowCou ...

  4. C# SQL优化 及 Linq 分页

    每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客!当然,希望将来的一天,某位老板看到此博客,给你的程序员职工加点薪资吧!因为程序员的世界除了苦逼就是沉默.我眼中的程序员大多都不 ...

  5. Linq分页查询

    //Linq分页查询 int pageIndex = Convert.ToInt32(HttpContext.Current.Request["PageIndex"]); int ...

  6. sql转Linq的工具

    本文转载:http://www.cnblogs.com/huangxincheng/archive/2011/05/12/2044990.html 介绍一个小工具 Linqer   这些天写Linq挺 ...

  7. Js处理数据——前端分页工具

    这几天有小伙伴讨论起了分页的相关问题,这里我也简单讲下前端如何简单便捷的利用Js(库)写出优雅,好用的分页工具. 分页是个很简单又超多接触的技术点,粗略来讲分如下两种: 真分页--每次根据页码.页大小 ...

  8. Linq分页

    /// <summary> /// Linq分页 /// </summary> ;//每页条数 ;//总条数 ;//当前第几页 public static string con ...

  9. PHP常用之封装分页工具类

    分页基本上是每个项目都会使用到的,所以呢,把它封装成一个工具类,以后直接调用就可以了(虽然TP框架的灰常强大,但是自己封一个也未尝不可.),这样既省时又省力还赚'工分'. 我封的这个分页工具类还比较完 ...

随机推荐

  1. leetcode题解:Search for a Range (已排序数组范围查找)

    题目: Given a sorted array of integers, find the starting and ending position of a given target value. ...

  2. MongoDB系列四:解决secondary的读操作

    http://blog.itpub.net/26812308/viewspace-2124660/ 在Replica sets 中的secondary节点默认是不可读的.使用Replica Sets实 ...

  3. nginx静态资源配置

    解决EE工程中静态文件显示问题 在工程中本地测试没有问题,发现使用nginx配置了路径的页面,会获取不到相应页面的静态文件问题 静态文件的路径类似为: http://localhost:8080/sa ...

  4. JStorm的Metrics含义

    附录:Metrics含义 MemoryUsed cluster/topology/worker使用到的物理内存HeapMemory cluster/topology/worker JVM使用到的堆内存 ...

  5. fabricjs 自定义类型

    https://stackoverflow.com/questions/36660108/how-to-create-custom-fabricjs-object I have to create a ...

  6. 2017.3.31 spring mvc教程(七)多视图控制器

    学习的博客:http://elf8848.iteye.com/blog/875830/ 我项目中所用的版本:4.2.0.博客的时间比较早,11年的,学习的是Spring3 MVC.不知道版本上有没有变 ...

  7. jquery 获取table当前行值

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  8. mac查看端口占用

    Mac OS/Linux命令查询网络端口占用情况   netstat命令 netstat -an | grep 3306 3306替换成需要grep的端口号 lsof命令 通过list open fi ...

  9. 用二十秒记住几个PHP基础知识点

    数组: 索引数组:数组的键是整数的数组,从0開始. 关联数组:数组的键是字符串的数组 //索引数组 $arr=array('I','love','you'); //关联数组 $arr0=array(' ...

  10. How to Start a New Cocos2d-x Game for version 3.0

    This documentation will show you how to use cocos console to create and run a new project. Runtime R ...