PaginationX 1.0.1

dotnet add package PaginationX --version 1.0.1
                    
NuGet\Install-Package PaginationX -Version 1.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="PaginationX" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PaginationX" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="PaginationX" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PaginationX --version 1.0.1
                    
#r "nuget: PaginationX, 1.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.
#:package PaginationX@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PaginationX&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=PaginationX&version=1.0.1
                    
Install as a Cake Tool

PaginationX

Una librería ligera y fácil de usar para implementar paginación en aplicaciones .NET.

NuGet License: MIT

📋 Características

  • ✅ Fácil de usar con LINQ y Entity Framework Core
  • ✅ Clase PagedResult<T> con información completa de paginación
  • ✅ Validación automática de parámetros de paginación
  • ✅ Compatible con .NET 6.0 y superior
  • ✅ Sin dependencias externas

📦 Instalación

Instala el paquete NuGet usando la CLI de .NET:

dotnet add package PaginationX

O a través del Package Manager Console en Visual Studio:

Install-Package PaginationX

🚀 Uso Rápido

Ejemplo Básico con Entity Framework Core

using PaginationX;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    private readonly ApplicationDbContext _context;

    public ProductsController(ApplicationDbContext context)
    {
        _context = context;
    }

    [HttpGet]
    public async Task<ActionResult<PagedResult<Product>>> GetProducts(
        [FromQuery] PaginationRequest pagination)
    {
        // Obtener el total de registros
        var totalCount = await _context.Products.CountAsync();

        // Obtener los items paginados
        var items = await _context.Products
            .OrderBy(p => p.Name)
            .Skip((pagination.PageNumber - 1) * pagination.PageSize)
            .Take(pagination.PageSize)
            .ToListAsync();

        // Crear el resultado paginado
        var result = new PagedResult<Product>(
            items, 
            totalCount, 
            pagination.PageNumber, 
            pagination.PageSize
        );

        return Ok(result);
    }
}

Ejemplo con LINQ en Memoria

using PaginationX;

public class UserService
{
    private readonly List<User> _users;

    public PagedResult<User> GetUsers(PaginationRequest pagination)
    {
        var totalCount = _users.Count;

        var items = _users
            .OrderBy(u => u.LastName)
            .Skip((pagination.PageNumber - 1) * pagination.PageSize)
            .Take(pagination.PageSize)
            .ToList();

        return new PagedResult<User>(
            items, 
            totalCount, 
            pagination.PageNumber, 
            pagination.PageSize
        );
    }
}

Ejemplo con Filtros

[HttpGet("search")]
public async Task<ActionResult<PagedResult<Product>>> SearchProducts(
    [FromQuery] string searchTerm,
    [FromQuery] PaginationRequest pagination)
{
    var query = _context.Products.AsQueryable();

    // Aplicar filtros
    if (!string.IsNullOrEmpty(searchTerm))
    {
        query = query.Where(p => p.Name.Contains(searchTerm));
    }

    var totalCount = await query.CountAsync();

    var items = await query
        .OrderBy(p => p.Name)
        .Skip((pagination.PageNumber - 1) * pagination.PageSize)
        .Take(pagination.PageSize)
        .ToListAsync();

    var result = new PagedResult<Product>(
        items, 
        totalCount, 
        pagination.PageNumber, 
        pagination.PageSize
    );

    return Ok(result);
}

📖 Documentación de API

PaginationRequest

Clase para recibir parámetros de paginación desde el cliente.

Propiedades:

Propiedad Tipo Descripción Valor por Defecto Validación
PageNumber int Número de página actual 1 Mínimo: 1
PageSize int Cantidad de items por página 10 Máximo: 50

Ejemplo de Uso:

// En un controlador API
[HttpGet]
public IActionResult GetItems([FromQuery] PaginationRequest pagination)
{
    // pagination.PageNumber y pagination.PageSize están validados automáticamente
}

Ejemplo de Request desde Cliente:

GET /api/products?PageNumber=2&PageSize=20

PagedResult<T>

Clase que encapsula los resultados paginados con metadatos.

Propiedades:

Propiedad Tipo Descripción
Items List<T> Lista de items de la página actual
CurrentPage int Número de página actual
TotalPages int Total de páginas disponibles
PageSize int Tamaño de página
TotalCount int Total de registros en la base de datos
HasPreviousPage bool Indica si existe una página anterior
HasNextPage bool Indica si existe una página siguiente

Ejemplo de Response JSON:

{
  "items": [
    { "id": 11, "name": "Producto 11" },
    { "id": 12, "name": "Producto 12" }
  ],
  "currentPage": 2,
  "totalPages": 5,
  "pageSize": 10,
  "totalCount": 50,
  "hasPreviousPage": true,
  "hasNextPage": true
}

🎯 Ejemplos Avanzados

Método de Extensión para IQueryable

Puedes crear un método de extensión para simplificar aún más el uso:

public static class QueryableExtensions
{
    public static async Task<PagedResult<T>> ToPagedResultAsync<T>(
        this IQueryable<T> query,
        PaginationRequest pagination)
    {
        var totalCount = await query.CountAsync();

        var items = await query
            .Skip((pagination.PageNumber - 1) * pagination.PageSize)
            .Take(pagination.PageSize)
            .ToListAsync();

        return new PagedResult<T>(
            items,
            totalCount,
            pagination.PageNumber,
            pagination.PageSize
        );
    }
}

// Uso
var result = await _context.Products
    .OrderBy(p => p.Name)
    .ToPagedResultAsync(pagination);

Ejemplo con Automapper

[HttpGet]
public async Task<ActionResult<PagedResult<ProductDto>>> GetProducts(
    [FromQuery] PaginationRequest pagination)
{
    var totalCount = await _context.Products.CountAsync();

    var items = await _context.Products
        .OrderBy(p => p.Name)
        .Skip((pagination.PageNumber - 1) * pagination.PageSize)
        .Take(pagination.PageSize)
        .ProjectTo<ProductDto>(_mapper.ConfigurationProvider)
        .ToListAsync();

    var result = new PagedResult<ProductDto>(
        items,
        totalCount,
        pagination.PageNumber,
        pagination.PageSize
    );

    return Ok(result);
}

🔧 Prerrequisitos

  • .NET 6.0 o superior

📄 Licencia

Este proyecto está licenciado bajo la Licencia MIT - ver el archivo LICENSE para más detalles.

🤝 Contribuciones

Las contribuciones son bienvenidas. Por favor, abre un issue o un pull request en el repositorio de GitHub.

👤 Autor

guevararogeljj

📞 Soporte

Si tienes alguna pregunta o problema, por favor abre un issue en el repositorio de GitHub.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
1.0.1 367 8/6/2025
1.0.0 398 8/6/2025