LINQ分页工具
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分页工具的更多相关文章
- c#分页工具类,完美实现List分页
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Proje ...
- Linq学习工具及Lamada表达式
好东西.转载一个.以备学习 Linq学习工具: http://www.linqpad.net/ Lamada表达式: Func<int, int, int> IntPow = (x ...
- Linq 分页不可缺少的两个方法
//LINQ分页的方法 //1.获取总页数 public int GetPageCount(int pageSize)//pageSize是每页的行数 { //先查出总共有多少行 int rowCou ...
- C# SQL优化 及 Linq 分页
每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客!当然,希望将来的一天,某位老板看到此博客,给你的程序员职工加点薪资吧!因为程序员的世界除了苦逼就是沉默.我眼中的程序员大多都不 ...
- Linq分页查询
//Linq分页查询 int pageIndex = Convert.ToInt32(HttpContext.Current.Request["PageIndex"]); int ...
- sql转Linq的工具
本文转载:http://www.cnblogs.com/huangxincheng/archive/2011/05/12/2044990.html 介绍一个小工具 Linqer 这些天写Linq挺 ...
- Js处理数据——前端分页工具
这几天有小伙伴讨论起了分页的相关问题,这里我也简单讲下前端如何简单便捷的利用Js(库)写出优雅,好用的分页工具. 分页是个很简单又超多接触的技术点,粗略来讲分如下两种: 真分页--每次根据页码.页大小 ...
- Linq分页
/// <summary> /// Linq分页 /// </summary> ;//每页条数 ;//总条数 ;//当前第几页 public static string con ...
- PHP常用之封装分页工具类
分页基本上是每个项目都会使用到的,所以呢,把它封装成一个工具类,以后直接调用就可以了(虽然TP框架的灰常强大,但是自己封一个也未尝不可.),这样既省时又省力还赚'工分'. 我封的这个分页工具类还比较完 ...
随机推荐
- 学习一些和redux一样作用的mobx知识
两个组件:mobx和mobx-react 英文文档:https://mobx.js.org/refguide/object.html 中文文档:https://cn.mobx.js.org/ 样例:h ...
- C中存储分区详解
一. 在c中分为这几个存储区:栈(stack),堆(heap),代码段(text),数据段(data),bss 段,常量存储区,1.栈(stack):由编译器自动分配释放自动分配,自动回收:栈区里面存 ...
- iOS常用第三方库大全,史上最全第三方库收集
下拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UITableVie ...
- selfshadow
realtime rendering v3 page 351 Moire pattern sruface acne artifacts ----------------------- 用 setsta ...
- Unity3D的三种坐标系
来自:http://blog.csdn.net/luxiaoyu_sdc/article/details/13168497 1, World Space(世界坐标): 我们在场景中添加物体(如:Cub ...
- Memcached进程挂掉自动重启脚本
vim memcached_check.sh #!/bin/sh #check memcached process and restart if down PATH=$PATH:/opt/env/ ...
- 500 lines or less
今天碰到一本书 <500 lines or less>突然就想在博客上记录一下自己的阅读经历了. 现在记录一下这本书的地址 http://aosabook.org/en/index.htm ...
- PHP curl post header
第三方教程推荐:https://www.cnblogs.com/CHEUNGKAMING/p/5717429.html
- SRIO常用缩写
HELLO:Header Encoded Logical Layer Optimized (HELLO) format FTYPE:format type TTYPE:transaction type ...
- lua学习笔记(五)
语句 赋值 多重赋值 a, b, c, d = 1, 2, 3, 4 a, b, c = 1, 2 assert(c == ni ...