TS.EntityFrameworkCore.Pagination 8.0.1

dotnet add package TS.EntityFrameworkCore.Pagination --version 8.0.1
NuGet\Install-Package TS.EntityFrameworkCore.Pagination -Version 8.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TS.EntityFrameworkCore.Pagination" Version="8.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TS.EntityFrameworkCore.Pagination --version 8.0.1
#r "nuget: TS.EntityFrameworkCore.Pagination, 8.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TS.EntityFrameworkCore.Pagination as a Cake Addin
#addin nuget:?package=TS.EntityFrameworkCore.Pagination&version=8.0.1

// Install TS.EntityFrameworkCore.Pagination as a Cake Tool
#tool nuget:?package=TS.EntityFrameworkCore.Pagination&version=8.0.1

Dependency

This library was created by .Net 8

Install

dotnet add package EntityFrameworkCore.Pagination

Use

var products = await _context.Products
                .ToPagedListAsync(pageNumber, pageSize);

Result

{
  "datas": [
    {
      "id": 1,
      "name": "Product1",
      "price": 10
    },
    ...
  ],
  "pageNumber": 1,
  "pageSize": 15,
  "totalPages": 67,
  "totalCount": 670,
  "isFirstPage": true,
  "isLastPage": false
}

Methods

This library have one methods and one class.

invoke

public static class PagesListQuerableExtensions
    {
        public static async Task<PaginationResult<T>> ToPagedListAsync<T>(
            this IQueryable<T> source,
            int pageNumber,
            int pageSize,
            CancellationToken cancellationToken = default)
            where T : class
        {
            var count = await source.CountAsync();
            if(count>0) { 
            var items = await source
                .Skip((pageNumber-1) * pageSize)
                .Take(pageSize)
                .AsNoTracking()
                .ToListAsync(cancellationToken);

            return new(items,pageNumber, pageSize,count);
            }
            return new(null, 0, 0, 0);
        }

    }
public class PaginationResult<T>
    {
        public PaginationResult(IList<T> datas,int pageNumber, int pageSize, int totalCount)
        {
            Datas = datas;
            PageNumber = pageNumber;
            PageSize = pageSize;
            TotalPages = (totalCount + pageSize) > 0 ? (int)Math.Ceiling(totalCount / (double)pageSize) : 0;
            TotalCount = totalCount;
            IsFirstPage = PageNumber == 1;
            IsLastPage = PageNumber == TotalPages;
        }
        public IList<T> Datas { get; set; }
        public int PageNumber { get; set; }
        public int PageSize { get; set; }
        public int TotalPages { get; set; }
        public int TotalCount { get; set; }
        public bool IsFirstPage { get; set; }
        public bool IsLastPage { get; set; }
    }
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.1 64 4/22/2024

Fixed Readme