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. Springboot项目创建文件中相对路径问题

    Springboot项目创建文件中相对路径问题 原代码: String location = "./src/main/resources/UsersFiles/" + userId ...

  2. Spring - MVC - thymeleaf 缓存关闭

    1. 概述 spring 配合 thymeleaf 关闭页面缓存 2. 背景 最近复习 spring 找了本书叫 spring in action 5th 本人水平有限 书还写得那么难 调试中遇到了问 ...

  3. 【C语言】(指针) 将两个数排序

    原理就不讲了,这里用来理解指针的使用方法 代码1: #include <stdio.h> int main() { int a, b;/* 实际变量的声明 */ int* p, * q;/ ...

  4. javaScript中的querySelector和querySelectorAll

    querySelector和querySelectorAll是W3C提供的 新的查询接口,其主要特点如下: 1.querySelector只返回匹配的第一个元素,如果没有匹配项,返回null. 2.q ...

  5. report_delay_calculation/check_timing/report_annotated_parasitics/report_analysis_coverge

    如何debug 一颗cell 或一段net 的delay,  常用的办法是用report_delay_calculation 报这颗cell 或这段net, 会得到形式如下的report, 从该rep ...

  6. Java日期时间API系列13-----Jdk8中java.time包中的新的日期时间API类,时间类转换,Date转LocalDateTime,LocalDateTime转Date等

    从前面的系列博客中可以看出Jdk8中java.time包中的新的日期时间API类设计的很好,但Date由于使用仍非常广泛,这就涉及到Date转LocalDateTime,LocalDateTime转D ...

  7. php常用函数归纳

    php常用函数归纳: /** * 截取指定长度的字符 * @param type $string 内容 * @param type $start 开始 * @param type $length 长度 ...

  8. Abaqus 粘聚力模型(Cohesive Model)

    目录 1. 问题描述 2. 有限元模型建立--Cohesive单元 3. 有限元模型建立--接触方法 Abaqus提供了两种方法模拟胶结特性: 使用Cohesive单元模拟胶结,通过定义材料属性和截面 ...

  9. ListView 基础列表组件、水平 列表组件、图标组件

    一.Flutter 列表组件概述 列表布局是我们项目开发中最常用的一种布局方式.Flutter 中我们可以通过 ListView 来定义 列表项,支持垂直和水平方向展示.通过一个属性就可以控制列表的显 ...

  10. django的静态文件配置和路由控制

    上一篇写到刚建完django项目,此时我登录页面中调用了js文件,执行后发现报错了找不到js这个文件 目录结构如图所示: <!DOCTYPE html> <html lang=&qu ...