NestXRepository.Core 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NestXRepository.Core --version 2.0.0
                    
NuGet\Install-Package NestXRepository.Core -Version 2.0.0
                    
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="NestXRepository.Core" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NestXRepository.Core" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NestXRepository.Core" />
                    
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 NestXRepository.Core --version 2.0.0
                    
#r "nuget: NestXRepository.Core, 2.0.0"
                    
#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 NestXRepository.Core@2.0.0
                    
#: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=NestXRepository.Core&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NestXRepository.Core&version=2.0.0
                    
Install as a Cake Tool

NestXRepository.Core

Librería de acceso a datos multi-estrategia para .NET 10+ con soporte para Dapper y Entity Framework Core, con arquitectura multi-motor preparada para PostgreSQL, SQL Server y MySQL.

Instalación

dotnet add package NestXRepository.Core

Características

  • Dual ORM: Dapper (DP*) para alto rendimiento + EF Core (EF*) para operaciones ORM completas
  • Multi-Motor: Arquitectura con ISqlDialect para soportar múltiples SGBD
  • BulkInsert: Inserción masiva usando PostgreSQL BINARY COPY
  • Foreign Keys: Carga automática de relaciones foráneas
  • SoftDelete: Borrado lógico con soporte para FK
  • Paginación: Built-in para consultas grandes
  • CancellationToken: Soporte completo para operaciones cancelables
  • Unit of Work: Transacciones compartidas entre Dapper y EF Core

ESTRUCTURA BASE

├── Dialects/
│   ├── ISqlDialect.cs           # Interfaz para abstracción de motores
│   ├── PostgreSqlDialect.cs     # Implementación PostgreSQL
│   ├── SqlServerDialect.cs      # Implementación SQL Server (preparada)
│   └── MySqlDialect.cs          # Implementación MySQL (preparada)
├── Interfaces/
│   └── IGenericRepository.cs
├── Repositories/
│   ├── GenericRepository.cs 
│   ├── ConnectionProvider.cs
│   ├── BulkOperationsHelper.cs
│   └── ServiceCollectionExtensions.cs
├── unit/
│   ├── IDapperUnitOfWork.cs
│   └── DapperUnitOfWork.cs
└── README.md

Arquitectura Multi-Motor

La librería usa el patrón Dialect para abstraer las diferencias entre motores SQL:

// PostgreSQL (default)
var repo = new GenericRepository<Product>(context, connectionString);

// SQL Server (próximamente)
var repo = new GenericRepository<Product>(context, connectionString, new SqlServerDialect());

// MySQL (próximamente)
var repo = new GenericRepository<Product>(context, connectionString, new MySqlDialect());

Dialectos disponibles

Dialecto Estado Características
PostgreSqlDialect Activo = ANY(@Ids), LIMIT/OFFSET, RETURNING
SqlServerDialect Preparado IN @Ids, TOP/OFFSET FETCH, OUTPUT
MySqlDialect Preparado IN @Ids, LIMIT/OFFSET, LAST_INSERT_ID()

Inicio Rápido

Opción 1: Con AddGenericRepository (Recomendado)

// Program.cs
using GenericRepository.Core.Repositories;

var builder = WebApplicationBuilder.CreateBuilder(args);

// Registrar DbContext
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<MyDbContext>(options =>
    options.UseNpgsql(connectionString));

// ✨ Una línea para auto-registrar todos los IRepository<T>
builder.Services.AddGenericRepository<MyDbContext>(connectionString);

var app = builder.Build();

Opción 2: Con Unit of Work (Para transacciones complejas)

builder.Services.AddGenericRepositoryWithUnitOfWork<MyDbContext>(connectionString);

Uso en Servicios

public class ProductService
{
    private readonly IGenericRepository<Product> _products;
    private readonly IGenericRepository<Category> _categories;

    public ProductService(
        IGenericRepository<Product> products,
        IGenericRepository<Category> categories)
    {
        _products = products;
        _categories = categories;
    }

    public async Task<Product?> GetProductByNameAsync(string name)
    {
        // Queries con Dapper (alto rendimiento)
        return await _products.DPGet(
            p => p.Name == name && p.IsActive,
            requiredFK: true
        );
    }

    public async Task<List<Product>> GetAllWithCategoriesAsync()
    {
        return await _products.DPGetAll(
            top: 100,
            orderBy: "\"Name\" ASC",
            requiredFK: false,
            includes: p => p.Category
        );
    }

    public async Task CreateProductAsync(Product product)
    {
        var newId = await _products.EFAdd<int>(product);
        product.Id = newId;
    }

    public async Task<(List<Product> Data, int TotalRecords, int TotalPages)> 
        GetPaginatedAsync(int page, int pageSize)
    {
        return await _products.DPGetPaginatedAsync(
            pageNumber: page,
            pageSize: pageSize,
            whereExpression: p => p.IsActive,
            requiredFK: true
        );
    }
}

Interfaces principales

Interfaz Descripción
IGenericRepository<T> Operaciones CRUD completas (DP* + EF*)
IDapperUnitOfWork Transacciones compartidas

Métodos principales

Consultas (DP* - Dapper)

Task<T> DPGet(whereExpression, orderBy?, requiredFK?, includes)
Task<List<T>> DPGetAll(whereExpression?, top?, orderBy?, requiredFK?, includes)
Task<(IEnumerable<T> Data, int TotalRecords, int TotalPages)> DPGetPaginatedAsync(...)
Task<bool> DPExistsAsync(whereExpression)

Consultas (EF* - Entity Framework)

Task<T?> EFGetFirst(whereExpression?, cancellationToken, includes)
Task<List<T>> EFGetAllAsync(whereExpression?, orderBy?, orderByDesc?, top?, ct, includes)
Task<(List<T> Data, int TotalRecords, int TotalPages)> EFGetPaginatedAsync(...)
Task<bool> EFExistsAsync(whereExpression, cancellationToken)

Inserciones

int BulkInsert(List<T> data, bool includeForeignKeys = false)  // BINARY COPY
Task<TResult> EFAdd<TResult>(T entity, cancellationToken)
Task<int> EFAddRange(List<T> entities, cancellationToken)
TResult DPAdd<TResult>(T entity)
int DPAddRange(List<T> entities)

Actualizaciones

Task<int> EFUpdate(T entity, cancellationToken)
Task<int> EFUpdateWithFK(T entity, ct, navigationProperties)
Task<int> EFUpdateRange(IEnumerable<T> entities, cancellationToken)
Task<int> DPUpdate(T entity, whereExpression)
Task<int> DPUpdatePartialAsync(updateFields, whereExpression, parameters?)

Eliminaciones

Task<int> DPDelete(T entity)
Task<int> DPDeleteRange(IEnumerable<T> entities)
Task<int> EFSoftDelete(T entity, userDeleted?, cancellationToken)
Task<int> EFSoftDeleteWithFK(T entity, userDeleted?, cancellationToken)
Task<int> DPSoftDelete(T entity, userDeleted?)

Requisitos

  • .NET 10.0+
  • PostgreSQL 12+
  • Npgsql 9.0+
  • Entity Framework Core 10.0+
  • Dapper 2.1+

Licencia

Propietaria - NestX Software © 2025

Test

dotnet test --verbosity minimal 2>&1 | Select-String "Passed|Failed|Error|Test Run|Total"

dotnet test --logger "console;verbosity=detailed"

dotnet test --logger "console;verbosity=detailed" 2>&1 | Select-String "Passed|Failed|ms)|entities"

TEST DAPPER

dotnet test GenericRepository.Core.Tests/GenericRepository.Core.Tests.csproj --filter "FullyQualifiedName~DPRepository" --logger "console;verbosity=detailed"

TEST EF

dotnet test GenericRepository.Core.Tests/GenericRepository.Core.Tests.csproj --filter "FullyQualifiedName~EFRepository" --logger "console;verbosity=detailed"

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.

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
2.3.3 131 6/14/2026
2.3.1 1,604 4/18/2026
2.2.0 311 4/15/2026
2.1.0 123 4/14/2026
2.0.3 128 4/1/2026
2.0.2 119 3/20/2026
2.0.1 118 2/27/2026
2.0.0 122 2/27/2026
1.1.8 131 1/4/2026
1.1.7 144 1/4/2026
1.1.6 140 1/2/2026
1.1.5 139 12/26/2025
1.1.4 449 12/11/2025
1.1.3 688 12/1/2025
1.1.2 149 11/29/2025
1.1.1 211 11/25/2025
1.1.0 216 7/7/2025
1.0.9 213 7/2/2025
1.0.8 206 6/25/2025
1.0.7 168 5/31/2025
Loading failed