using System;
using System.Collections.Generic;
using System.Linq; namespace Microestc.PaginatedList
{
public class PaginatedList<TResult> : List<TResult>
{
public PaginatedList() : base() { } public PaginatedList(IEnumerable<TResult> items, int totalCount, int pageIndex, int pageSize) : base(items)
{
TotalCount = totalCount;
PageCount = (totalCount + pageSize - ) / pageSize;
PageIndex = pageIndex;
PageSize = pageSize;
HasPrev = pageIndex > ;
HasNext = pageIndex < PageCount;
} public virtual int TotalCount { get; private set; } public virtual int PageCount { get; private set; } public virtual int PageIndex { get; private set; } public virtual int PageSize { get; private set; } public virtual bool HasPrev { get; private set; } public virtual bool HasNext { get; private set; }
} public static class PaginatedListExtensions
{
public static PaginatedList<TResult> PaginatedList<TResult>(this IEnumerable<TResult> source, int pageIndex, int pageSize)
{
var count = source.Count();
var items = source.Skip((pageIndex - ) * pageSize).Take(pageSize);
return new PaginatedList<TResult>(items, count, pageIndex, pageSize);
} public static PaginatedList<TResult> PaginatedList<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector, int pageIndex, int pageSize)
{
var count = source.Count();
var items = source.Skip((pageIndex - ) * pageSize).Take(pageSize).Select(selector);
return new PaginatedList<TResult>(items, count, pageIndex, pageSize);
}
}
}

c# 分页 PaginatedList<TResult>的更多相关文章

  1. MVC如何使用开源分页插件shenniu.pager.js

    最近比较忙,前期忙公司手机端接口项目,各种开发+调试+发布现在几乎上线无问题了:虽然公司项目忙不过在期间抽空做了两件个人觉得有意义的事情,一者使用aspnetcore开发了个人线上项目(要说线上其实只 ...

  2. EF分页中的陷阱

    (一) 前言                                                                   EF使用非常简单,但是如果使用不当就会误入EF陷阱中. ...

  3. Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 排序、筛选、分页以及分组

    Sorting, filtering, paging, and grouping 7 of 8 people found this helpful By Tom Dykstra The Contoso ...

  4. 关于EF分页查询报错(Count must have a non-negative value.)的解决方案

    具体的异常信息如下,一开始没有写日志只看到错误信息:Count must have a non-negative value.,从表面意思可以看出来是Count值出现了负数,所以报错,查了半天的原因也 ...

  5. jquery 分页控件2

    jquery 分页控件(二) 上一章主要是关于分页控件的原理,代码也没有重构.在这一章会附上小插件的下载链接,插件主要就是重构逻辑部分,具体可以下载源文件看下,源代码也有注释.为了测试这个插件是能用的 ...

  6. 请求Url返回数据较大,使结果分页获取

    首先创建了一个单元测试,如下项目视图: 分页结果映射类PageResult的编写: using System; using System.Collections.Generic; using Syst ...

  7. asp.net core下一个简单的分页技术

    在做web应用的时候免不了要对数据进行分页,我最近在做asp.net core的开发的时候就遇到了这个需求,现在简单的记录一下: public class PaginatedList<T> ...

  8. IBatis的分页研究

    IBatis的分页研究 博客分类: Ibatis学习   摘自: http://cpu.iteye.com/blog/311395 yangtingkun   Oracle分页查询语句 ibaits. ...

  9. 一、iBatis进行分页查询

    1.ibatis理解: iBatis属于半自动化的ORM框架,我们需要编写SQL语句,由iBatis进行数据库访问,返回结果.而iBatis可以为我们做的更多,比如对查询参数集合.结果.分页查询.事务 ...

随机推荐

  1. next.config.js

    const configs = { // 编译文件的输出目录 distDir: 'dest', // 是否给每个路由生成Etag generateEtags: true, // 页面内容缓存配置 on ...

  2. SpringBoot集成SwaggerUI

    1.在module下的pom.xml中引用相关插件 引用swagger插件并用参数化版本信息,如下 <?xml version="1.0" encoding="UT ...

  3. wix中ServiceInstall与ServiceControl的关系

    上面那篇之后其实还踩了个坑,安装Windows服务确实是打包进去了,但死活不能安装成功,从提示和日志看正好是Windows服务处理的地方出现了异常.以为是服务启动失败,但是服务在服务管理里手动启动是没 ...

  4. .net core 通过代码创建数据库表

    0.结构: 1.API using System; using System.Collections.Generic; using System.IO; using System.Linq; usin ...

  5. 从游击队到正规军(三):基于Go的马蜂窝旅游网分布式IM系统技术实践

    本文由马蜂窝技术团队电商交易基础平台研发工程师"Anti Walker"原创分享. 一.引言 即时通讯(IM)功能对于电商平台来说非常重要,特别是旅游电商. 从商品复杂性来看,一个 ...

  6. js实现上移下移

    直接上代码 //上移 var $up = $(".up") $up.click(function () { var $tr = $(this).parents("tr&q ...

  7. C语言笔记 10_文件读写&预处理器

    文件读写 上一章我们讲解了 C 语言处理的标准输入和输出设备.本章我们将介绍 C 程序员如何创建.打开.关闭文本文件或二进制文件. 一个文件,无论它是文本文件还是二进制文件,都是代表了一系列的字节.C ...

  8. 吴裕雄 python 机器学习——数据预处理包裹式特征选取模型

    from sklearn.svm import LinearSVC from sklearn.datasets import load_iris from sklearn.feature_select ...

  9. cmake 单个目录多个文件的情况

    参考:https://www.hahack.com/codes/cmake/# 源文件一共有三个:main.cpp.MathFunctions.h.MathFunctions.cpp 文件内容分别如下 ...

  10. 获取自增长的id值

    单个: <insert id="create" parameterType="com.dto.Cou" useGeneratedKeys="tr ...