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. solrCloud分布式检索流程

    FROM: http://blog.csdn.net/duck_genuine/article/details/17014991 好久没写solr的文章了,刚好需要在公司作个分享,先总结一些先. 引用 ...

  2. autocomplete属性在谷歌浏览器不起作用

    大家都知道autocomplete属性是表单字段中的HTML5新属性,该属性有两种状态值,分别为"on" 和 "off",该属性可省略:省略属性值后默认值为&q ...

  3. [转] docker rmi命令-删除image

    原文:http://www.simapple.com/341.html ---------------------------------------------------------------- ...

  4. [Algorithm] Heap data structure and heap sort algorithm

    Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...

  5. TFS 设置(转)

    一 参考以下两个链接进行相关软件的安装和用户权限配置: http://www.cnblogs.com/WilsonWu/archive/2011/11/24/2261674.html http://w ...

  6. <p>在静态类junit.framework.Assert或者静态类org.junit.Assert中存在下面几个方法</p>

    在静态类junit.framework.Assert或者静态类org.junit.Assert中存在下面几个方法 1.assertEquals()方法,用来查看对象中存的值是否是期待的值,与字符串比較 ...

  7. App功能测试的7大注意点

    转载于:https://mp.weixin.qq.com/s/27DZ1EQVpl-gb4S7n-He4g 01 运行 1)App安装完成后的试运行,可正常打开软件. 2)App打开测试,是否有加载状 ...

  8. Socket 异步通信示例

    这个项目是一个控制台应用程序: 服务器端: using System; using System.Net; using System.Net.Sockets; using System.Text; u ...

  9. Delphi 数据类型列表

    分类 范围 字节 备注 简单类型 序数 整数 Integer -2147483648 .. 2147483647 4 有符号32位 Cardinal 0 .. 4294967295 4 无符号32位 ...

  10. MySQL加入服务、设置password、改动password

    修正:加入MySQL服务时,能够不带版本.也就说以下的全部MySQL57能够直接写成MySQL!希望大家注意. MySQL安装好之后,往往还须要再做一些设置! 1.加入MySQL服务: 输入命令cmd ...