Plex.DataAccess.Base
8.0.55
See the version list below for details.
dotnet add package Plex.DataAccess.Base --version 8.0.55
NuGet\Install-Package Plex.DataAccess.Base -Version 8.0.55
<PackageReference Include="Plex.DataAccess.Base" Version="8.0.55" />
<PackageVersion Include="Plex.DataAccess.Base" Version="8.0.55" />
<PackageReference Include="Plex.DataAccess.Base" />
paket add Plex.DataAccess.Base --version 8.0.55
#r "nuget: Plex.DataAccess.Base, 8.0.55"
#:package Plex.DataAccess.Base@8.0.55
#addin nuget:?package=Plex.DataAccess.Base&version=8.0.55
#tool nuget:?package=Plex.DataAccess.Base&version=8.0.55
Plex.DataAccess.Base
A .NET 8 library that provides base classes for the Unit of Work and Repository patterns with EF Core. Supports dynamic multi-tenant connection strings, SQL Server and PostgreSQL, concurrency conflict auto-resolution, raw SQL connection factories for Dapper, and SQL Server JSON function mappings.
Features
- Unit of Work + Repository pattern —
UnitOfWorkBase,RepositoryBase, andDbContextBasewith full CRUD operations - Multi-provider — SQL Server and PostgreSQL, switchable per database via configuration
- Dynamic connection strings — per-request database targeting via
cx-dbandcx-serverHTTP headers (multi-tenant) - Concurrency handling — automatic retry on
DbUpdateConcurrencyException(up to 5 retries with entity reload) - Raw SQL connection factory —
SqlConnectionFactoryfor Dapper queries outside of EF Core - JSON function mappings —
JSON_VALUEandJSON_QUERYSQL Server functions usable in LINQ queries - Strongly-typed IDs —
TypedIdValueBasefor DDD-style typed ID value objects - EF Core options from config — command timeout, retry-on-failure, lazy loading, change tracking, query tracking, migrations, sensitive data logging all driven by
appsettings.json
Installation
dotnet add package Plex.DataAccess.Base
Configuration
Add these settings to your appsettings.json (all are optional — defaults shown):
{
"ConnectionStringKey": "DefaultConnection",
"ConnectionStrings": {
"DefaultConnection": "Server=%server%;Database=%db%;Trusted_Connection=True;"
},
"EfSqlCommandTimeOutInSecond": 300,
"EfSqlMaxRetryOnFailureCount": 0,
"EfEnableMigration": false,
"EfUseLazyLoading": false,
"EfUseChangeTrackingProxies": false,
"EfUseQueryTrackingBehavior": false,
"EfIsHandleDbUpdateConcurrency": true,
"EfEnableSensitiveDataLogging": false,
"AppSettings": {
"DbProviderMappings": {
"my-database-name": "mssql",
"my-pg-database": "postgresql"
}
}
}
| Setting | Default | Description |
|---|---|---|
EfSqlCommandTimeOutInSecond |
300 |
SQL command timeout in seconds |
EfSqlMaxRetryOnFailureCount |
0 |
Max automatic retries on transient failures (0 = disabled) |
EfEnableMigration |
false |
Run Database.Migrate() on context creation |
EfUseLazyLoading |
false |
Enable EF Core lazy loading proxies |
EfUseChangeTrackingProxies |
false |
Enable EF Core change tracking proxies |
EfUseQueryTrackingBehavior |
false |
If false, sets QueryTrackingBehavior.NoTracking |
EfIsHandleDbUpdateConcurrency |
true |
Auto-retry on concurrency conflicts |
EfEnableSensitiveDataLogging |
false |
Include parameter values in EF Core logs |
Usage
Define your DbContext
public class MyDbContext : DbContextBase
{
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }
public DbSet<Order> Orders => Set<Order>();
}
Define your Unit of Work
public class MyUnitOfWork : UnitOfWorkBase<MyDbContext>
{
public MyUnitOfWork(Func<MyDbContext> factory) : base(factory) { }
}
Define your Repository
public class OrderRepository : RepositoryBase<Order, MyUnitOfWork>, IOrderRepository
{
public OrderRepository(Func<MyUnitOfWork> unitOfWorkFactory) : base(unitOfWorkFactory) { }
}
Register in DI
// Pooled DbContext registration
builder.Services.RegisterDbContextPool<MyDbContext>();
// Standard DbContext registration
builder.Services.RegisterDbContext<MyDbContext>();
// With cache interceptor
builder.Services.RegisterDbContextPool<MyDbContext, MyCacheInterceptor>();
// Raw SQL connection factory for Dapper (scoped)
builder.Services.RegisterSqlConnectionFactory<ISqlConnectionFactory, SqlConnectionFactory>();
// Raw SQL connection factory for Dapper (singleton/pooled)
builder.Services.RegisterSqlConnectionFactoryPool<ISqlConnectionFactory, SqlConnectionFactory>();
Repository operations
// Query
var orders = repository.QueryableAsNoTracking(o => o.Status == "Active");
var order = await repository.FirstOrDefaultAsync(o => o.Id == orderId);
// Add with immediate save
await repository.SaveAddedAsync(newOrder);
// Update with immediate save
await repository.SaveUpdatedAsync(existingOrder);
// Remove with immediate save
await repository.SaveRemovedAsync(order);
// Save via Unit of Work
await unitOfWork.CommitAsync(cancellationToken);
JSON functions in LINQ queries
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
EfJsonExtensions.AddJsonValue(modelBuilder);
EfJsonQueryExtensions.AddJsonQuery(modelBuilder);
}
// Then use in queries:
var results = context.Orders
.Where(o => EfJsonExtensions.JsonValue(o.JsonData, "$.status") == "active");
API Reference
Interfaces
| Interface | Description |
|---|---|
IUnitOfWork |
Commit, change tracker, raw SQL connection |
IRepositoryBase<TEntity> |
Full CRUD with sync/async, tracking/no-tracking variants |
ISqlConnectionFactory |
Open sync/async raw SqlConnection for Dapper |
Base Classes
| Class | Description |
|---|---|
DbContextBase |
EF Core DbContext with auto-configuration from PlexDbContextOption |
UnitOfWorkBase<TContext> |
Abstract Unit of Work with concurrency retry |
RepositoryBase<TEntity, TUnitOfWork> |
Generic repository with 26 CRUD methods |
SqlConnectionFactory |
Raw SqlConnection manager for Dapper |
TypedIdValueBase |
DDD-style strongly-typed ID base class (wraps long?) |
Extension Methods
| Class | Methods |
|---|---|
ServiceCollectionExtensions |
RegisterDbContextPool, RegisterDbContext, RegisterSqlConnectionFactory, RegisterSqlConnectionFactoryPool |
DbContextOptionsExtensions |
AppendOptions<TContext> |
EfJsonExtensions |
JsonValue, AddJsonValue |
EfJsonQueryExtensions |
JsonQuery, AddJsonQuery |
Dependencies
| Package | Version |
|---|---|
| Microsoft.EntityFrameworkCore | 8.0.x |
| Microsoft.EntityFrameworkCore.SqlServer | 8.0.x |
| Microsoft.EntityFrameworkCore.Proxies | 8.0.x |
| Microsoft.Data.SqlClient | 5.2.x |
| Plex.Extensions.Configuration | 8.0.x |
| System.Text.Json | 8.0.x |
License
Plex-Solution Community Source-Available License — free for non-commercial use only.
| Product | Versions 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. |
-
net8.0
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.EntityFrameworkCore (>= 8.0.11)
- Microsoft.EntityFrameworkCore.Proxies (>= 8.0.11)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.11)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.11)
- Plex.Extensions.Configuration (>= 8.0.3)
- System.Text.Json (>= 8.0.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Plex.DataAccess.Base:
| Package | Downloads |
|---|---|
|
Plex.Security.AccessControl
Access control list |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.56 | 74 | 7/23/2026 |
| 8.0.55 | 78 | 7/23/2026 |
| 8.0.54 | 271 | 3/20/2025 |
| 8.0.53 | 249 | 3/20/2025 |
| 8.0.52 | 235 | 3/19/2025 |
| 8.0.51 | 229 | 3/19/2025 |
| 8.0.50 | 226 | 3/19/2025 |
| 8.0.49 | 226 | 3/18/2025 |
| 8.0.48 | 315 | 3/4/2025 |
| 8.0.47 | 210 | 3/3/2025 |
| 8.0.46 | 218 | 1/16/2025 |
| 8.0.45 | 215 | 1/6/2025 |
| 8.0.44 | 185 | 1/6/2025 |
| 8.0.43 | 389 | 12/24/2024 |
| 8.0.42 | 207 | 12/24/2024 |
| 8.0.41 | 257 | 12/17/2024 |
| 8.0.40 | 196 | 12/16/2024 |
| 8.0.39 | 273 | 11/14/2024 |
| 8.0.38 | 230 | 11/14/2024 |
| 8.0.37 | 337 | 10/24/2024 |
Update vulnerabilities package