NPv.DataAccess.Abstractions 2.6.0

dotnet add package NPv.DataAccess.Abstractions --version 2.6.0
                    
NuGet\Install-Package NPv.DataAccess.Abstractions -Version 2.6.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="NPv.DataAccess.Abstractions" Version="2.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NPv.DataAccess.Abstractions" Version="2.6.0" />
                    
Directory.Packages.props
<PackageReference Include="NPv.DataAccess.Abstractions" />
                    
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 NPv.DataAccess.Abstractions --version 2.6.0
                    
#r "nuget: NPv.DataAccess.Abstractions, 2.6.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 NPv.DataAccess.Abstractions@2.6.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=NPv.DataAccess.Abstractions&version=2.6.0
                    
Install as a Cake Addin
#tool nuget:?package=NPv.DataAccess.Abstractions&version=2.6.0
                    
Install as a Cake Tool

NPv.DataAccess.Abstractions

Minimal interface contract for generic repository access in .NET applications.

πŸ“’ Version status

  • v2.6 is the new stable version of NPv.DataAccess.Abstractions and is recommended for all new and existing integrations.
  • Previous versions are now considered out of service and are no longer maintained.

✨ Overview

This library defines core abstractions for working with persistent data in a clean, provider-agnostic way. It includes:

  • IGenericRepository β€” for standard CRUD operations on aggregate roots or entities
  • ISqlExecutor β€” for executing raw SQL queries and commands asynchronously

These abstractions are designed to support layered architectures, promote separation of concerns, and enable swapping implementations (e.g., EF Core, Dapper) with minimal friction.

🧱 Interfaces

IGenericRepository

Standard CRUD contract for entity-oriented persistence:

Task<TEntity?> GetAsync<TEntity>(Guid id, CancellationToken ct, IReadOnlyCollection<string>? includes = null);
Task<TEntity?> GetAsync<TEntity>(Expression<Func<TEntity, bool>>? filter, CancellationToken ct, IReadOnlyCollection<string>? includes = null);
Task<IEnumerable<TEntity>> ListAsync<TEntity>(
    CancellationToken ct,
    Expression<Func<TEntity, bool>>? filter = null,
    Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
    IReadOnlyCollection<string>? includes = null);
Task<IEnumerable<TEntity>> PageAsync<TEntity>(
    int page,
    int pageSize,
    CancellationToken ct,
    Expression<Func<TEntity, bool>>? filter = null,
    Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
    IReadOnlyCollection<string>? includes = null);
Task<int> CountAsync<TEntity>(CancellationToken ct, Expression<Func<TEntity, bool>>? filter = null);
Task AddAsync<TEntity>(TEntity entity, CancellationToken ct);
Task DeleteAsync<TEntity>(Guid id, CancellationToken ct);

Include examples (current behavior)

includes uses string-based navigation paths:

var order = await repo.GetAsync<Order>(
    id,
    ct,
    new[] { "Items", "Customer", "Customer.Address" });

var orders = await repo.ListAsync<Order>(
    ct,
    filter: x => x.Status == OrderStatus.Created,
    includes: new[] { "Items.Product" });

ISqlExecutor

Lightweight abstraction over raw SQL execution, ideal for high-performance scenarios using Dapper or similar tools:

Task<T> QueryFirstAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<T?> QueryFirstOrDefaultAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<T> QuerySingleAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<T?> QuerySingleOrDefaultAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<IEnumerable<T>> QueryAsync<T>(string sql, CancellationToken ct, object? parameters = null);
Task<int> ExecuteAsync(string sql, CancellationToken ct, object? parameters = null);

⏹️ CancellationToken

All async methods require a CancellationToken ct. Pass the application/request token from top-level boundaries so cancellation flows into repository/SQL layers. If no token is available, pass CancellationToken.None explicitly at the call site. Cancellation is propagated into EF Core/Dapper operations; OperationCanceledException is allowed to bubble.

public sealed class OrdersController(IGenericRepository repo)
{
    [HttpPost]
    public async Task<IActionResult> Create(CreateOrderRequest request, CancellationToken ct)
    {
        await repo.AddAsync(new Order { /* ... */ }, ct);
        return Ok();
    }
}

πŸ”§ Usage

Implement the interface in your data layer (e.g., using EF Core):

For IGenericRepository

public class EfGenericRepository : IGenericRepository { ... }

For ISqlExecutor

Implement using your SQL technology of choice, e.g. via Dapper:

public class DapperSqlExecutor : ISqlExecutor { ... }

Inject ISqlExecutor where you need to run raw SQL without managing connections or boilerplate manually.

πŸ“¦ Installation

This package is published as part of the NPv.Foundation.Net architecture.

To install via NuGet:

dotnet add package NPv.DataAccess.Abstractions
  • NPv.DataAccess.Ef – EF Core implementation of IGenericRepository
  • NPv.DataAccess.Dapper.Executor – Dapper-based implementation of ISqlExecutor

Author's Note

This library grew out of my long-standing personal interest in structuring and publishing open source packages. Over time, I’ve revisited and refined earlier internal utilities and ideas, giving them a more consistent shape and preparing them for wider reuse. Along the way, I’ve also taken the opportunity to explore how open source distribution and licensing work in the .NET ecosystem.

It’s a small step toward something I’ve always wanted to try β€” sharing practical, minimal tools that reflect years of learning, experimentation, and refinement.

Hopefully, someone finds it useful.

Nikolai πŸ˜›

βš–οΈ License

MIT β€” you are free to use this in commercial and open-source software.

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 (2)

Showing the top 2 NuGet packages that depend on NPv.DataAccess.Abstractions:

Package Downloads
NPv.DataAccess.Ef

NPv's IGenericRepository realisation for EF including: IDbContextFactory, IDbContextProvider, PerRequestDbContextProvider, ConsoleDbContextProvider

NPv.DataAccess.Dapper.Executor

Dapper-based implementation of ISqlExecutor for raw SQL access in .NET applications. Wraps common Dapper methods and manages connection lifecycle.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.6.0 164 2/11/2026
2.5.1 136 2/11/2026
2.5.0 116 2/11/2026