Plex.DataAccess.Base 8.0.56

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

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 patternUnitOfWorkBase, RepositoryBase, and DbContextBase with full CRUD operations
  • Multi-provider — SQL Server and PostgreSQL, switchable per database via configuration
  • Dynamic connection strings — per-request database targeting via cx-db and cx-server HTTP headers (multi-tenant)
  • Concurrency handling — automatic retry on DbUpdateConcurrencyException (up to 5 retries with entity reload)
  • Raw SQL connection factorySqlConnectionFactory for Dapper queries outside of EF Core
  • JSON function mappingsJSON_VALUE and JSON_QUERY SQL Server functions usable in LINQ queries
  • Strongly-typed IDsTypedIdValueBase for 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 51 7/23/2026
8.0.55 55 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
Loading failed

Update dependency packages information