NPv.DataAccess.Ef
2.3.0
See the version list below for details.
dotnet add package NPv.DataAccess.Ef --version 2.3.0
NuGet\Install-Package NPv.DataAccess.Ef -Version 2.3.0
<PackageReference Include="NPv.DataAccess.Ef" Version="2.3.0" />
<PackageVersion Include="NPv.DataAccess.Ef" Version="2.3.0" />
<PackageReference Include="NPv.DataAccess.Ef" />
paket add NPv.DataAccess.Ef --version 2.3.0
#r "nuget: NPv.DataAccess.Ef, 2.3.0"
#:package NPv.DataAccess.Ef@2.3.0
#addin nuget:?package=NPv.DataAccess.Ef&version=2.3.0
#tool nuget:?package=NPv.DataAccess.Ef&version=2.3.0
NPv.DataAccess.Ef
Pluggable EF Core infrastructure for a generic repository and a single explicit unit of work.
Read-side queries are expected to go through Dapper, completely bypassing this library.
π Breaking changes
v2.1.0
Breaking change planned for v2.1.0: CancellationToken is now required in repository async methods.
Pass the boundary token from controllers/workers so EF Core receives cancellation signals.
If no token is available, pass CancellationToken.None explicitly at the call site.
v2.0.0
- Target framework updated to
net10.0(droppednet9.0support).
This is a personal library that focuses on the latest .NET runtime to keep maintenance simple and enjoyable.
π¦ Version 1.3.x β Explicit Commit & Safe UoW
Overview
This library provides:
- A reusable
EfCoreGenericRepositoryfor standard CRUD operations (write path only) - A scoped
IDbContextProviderwith explicit commit semantics- No auto-commit on dispose
- No transaction management exposed to callers
- One unit of work = one
SaveChangesAsync()wrapped in a transaction
- Enhanced mapping conventions for entities and string fields
- Value generation using
GuidV7ValueGeneratorfor sequential GUIDs [LongText]attribute and defaultnvarchar(256)string mappings
Designed as a drop-in infrastructure layer for services, APIs, and background workers that rely on EF Core.
π Getting Started
- Add a reference to the package.
- Register your
DbContext,IDbContextProvider, and repository in your DI container. - Use the repository inside command handlers.
- Call
CommitAsync()once per unit of work.
β Example Setup
Define your application DbContext:
public class ApplicationContext(DbContextOptions<ApplicationContext> options) : DbContext(options)
{
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
foreach (var entityType in builder.Model.GetEntityTypes()
.Where(t => t.ClrType.IsSubclassOf(typeof(Entity))))
{
var entity = builder.Entity(entityType.ClrType);
entity.Property("Id")
.ValueGeneratedOnAdd()
.HasValueGenerator<GuidV7ValueGenerator>();
}
// Applies default mapping for strings to nvarchar(256)
DefaultString256MaxLengthMapping.ApplyMapping(builder);
}
}
π Usage Notes
- All string columns default to
nvarchar(256)unless[MaxLength]or[LongText]is applied. - Entity
Iduses a sequentialGuidV7for better index locality. DbContextProvideronly commits viaCommitAsync(); never on dispose.- For commands (writes), wrap execution in a unit of work and call
CommitAsync()only once at the end. - For queries (reads), use Dapper directly β EF Core is bypassed.
Example Command Handler
public sealed class CreateOrderHandler(IGenericRepository repo)
{
public async Task ExecuteAsync(CreateOrder cmd, CancellationToken ct)
{
var order = new Order { /* ... */ };
await repo.AddAsync(order, ct);
// No SaveChanges here!
}
}
// Somewhere in your pipeline:
await using var uow = scope.Resolve<IDbContextProvider>();
await handler.ExecuteAsync(command, ct);
await uow.CommitAsync(ct); // wraps SaveChanges in a transaction
βΉοΈ CancellationToken
All async repository methods now require a CancellationToken ct (no default) and propagate it to EF Core
operations. Pass the request token from the application layer so cancellation is honored end-to-end.
If no token is available, pass CancellationToken.None explicitly at the call site.
Cancellation is not suppressed: OperationCanceledException is allowed to propagate.
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 | 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
- Microsoft.EntityFrameworkCore (>= 10.0.3)
- NPv.DataAccess.Abstractions (>= 2.3.0)
- NPv.Domain.Core (>= 2.0.0)
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.5.1 | 121 | 4/22/2026 |
| 2.5.0 | 136 | 2/11/2026 |
| 2.4.2 | 113 | 2/11/2026 |
| 2.4.1 | 115 | 2/11/2026 |
| 2.4.0 | 111 | 2/10/2026 |
| 2.3.0 | 122 | 2/10/2026 |
| 2.2.0 | 119 | 2/8/2026 |
| 2.1.0 | 136 | 2/1/2026 |
| 2.0.2 | 134 | 1/11/2026 |
| 2.0.1 | 127 | 1/11/2026 |
| 2.0.0 | 219 | 12/24/2025 |
| 1.4.1 | 239 | 10/1/2025 |
| 1.4.0 | 225 | 10/1/2025 |
| 1.3.1 | 230 | 8/18/2025 |
| 1.3.0 | 266 | 8/8/2025 |
| 1.2.1 | 196 | 6/15/2025 |
| 1.2.0 | 210 | 6/14/2025 |
| 1.1.2 | 244 | 5/22/2025 |
| 1.1.1 | 214 | 5/22/2025 |
| 1.1.0 | 211 | 5/22/2025 |