NPv.DataAccess.Abstractions
2.5.0
See the version list below for details.
dotnet add package NPv.DataAccess.Abstractions --version 2.5.0
NuGet\Install-Package NPv.DataAccess.Abstractions -Version 2.5.0
<PackageReference Include="NPv.DataAccess.Abstractions" Version="2.5.0" />
<PackageVersion Include="NPv.DataAccess.Abstractions" Version="2.5.0" />
<PackageReference Include="NPv.DataAccess.Abstractions" />
paket add NPv.DataAccess.Abstractions --version 2.5.0
#r "nuget: NPv.DataAccess.Abstractions, 2.5.0"
#:package NPv.DataAccess.Abstractions@2.5.0
#addin nuget:?package=NPv.DataAccess.Abstractions&version=2.5.0
#tool nuget:?package=NPv.DataAccess.Abstractions&version=2.5.0
NPv.DataAccess.Abstractions
Minimal interface contract for generic repository access in .NET applications.
đĸ Version status
- v2.5 is the new stable version of
NPv.DataAccess.Abstractionsand 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 entitiesISqlExecutorâ 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<IReadOnlyList<TEntity>> ListAsync<TEntity>(
CancellationToken ct,
Expression<Func<TEntity, bool>>? filter = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>>? orderBy = null,
IReadOnlyCollection<string>? includes = null);
Task<IReadOnlyList<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
đ§Š Related packages
NPv.DataAccess.Efâ EF Core implementation ofIGenericRepositoryNPv.DataAccess.Dapper.Executorâ Dapper-based implementation ofISqlExecutor
| Product | Versions 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. |
-
net10.0
- NPv.Domain.Core (>= 2.0.0)
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.