RCommon.Persistence
2.4.1
dotnet add package RCommon.Persistence --version 2.4.1
NuGet\Install-Package RCommon.Persistence -Version 2.4.1
<PackageReference Include="RCommon.Persistence" Version="2.4.1" />
<PackageVersion Include="RCommon.Persistence" Version="2.4.1" />
<PackageReference Include="RCommon.Persistence" />
paket add RCommon.Persistence --version 2.4.1
#r "nuget: RCommon.Persistence, 2.4.1"
#:package RCommon.Persistence@2.4.1
#addin nuget:?package=RCommon.Persistence&version=2.4.1
#tool nuget:?package=RCommon.Persistence&version=2.4.1
RCommon.Persistence
Persistence abstraction layer for RCommon providing the repository pattern, unit of work, specification pattern, and named data store management. This package defines the core interfaces and base classes that ORM-specific implementations (EF Core, Dapper, Linq2Db) build upon.
Features
- Repository pattern with separate read-only and write-only interfaces for CQRS-friendly designs
- LINQ-enabled repositories exposing
IQueryable<T>for composable queries - Graph repositories with change tracking support for ORMs like Entity Framework Core
- SQL mapper repositories for micro-ORMs like Dapper
- Specification pattern support for encapsulating query logic
- Paginated query results via
IPaginatedList<T>with built-in ordering - Eager loading abstraction with
Include/ThenIncludechaining - Unit of work pattern with configurable transaction modes and isolation levels
- Named data store factory for managing multiple database connections
- Domain event tracking integrated into repository operations
- Soft delete -- automatic
!IsDeletedfiltering on reads and logical deletion on writes for entities implementingISoftDelete - Multitenancy -- automatic tenant filtering on reads and
TenantIdstamping on writes for entities implementingIMultiTenant - Fluent builder API for DI registration via
AddRCommon()
Installation
dotnet add package RCommon.Persistence
Usage
This package is typically used indirectly through a provider-specific package. However, you program against these abstractions in your application and domain layers:
// Inject repository abstractions into your services
public class OrderService
{
private readonly IGraphRepository<Order> _orderRepo;
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
public OrderService(IGraphRepository<Order> orderRepo, IUnitOfWorkFactory unitOfWorkFactory)
{
_orderRepo = orderRepo;
_unitOfWorkFactory = unitOfWorkFactory;
}
public async Task<Order> GetOrderAsync(int id)
{
return await _orderRepo.FindAsync(id);
}
public async Task<ICollection<Order>> GetPendingOrdersAsync()
{
return await _orderRepo.FindAsync(o => o.Status == OrderStatus.Pending);
}
public async Task<IPaginatedList<Order>> GetOrdersPagedAsync(int page, int pageSize)
{
return await _orderRepo.FindAsync(
o => o.IsActive,
o => o.CreatedDate,
orderByAscending: false,
pageNumber: page,
pageSize: pageSize);
}
public async Task PlaceOrderAsync(Order order)
{
using var unitOfWork = _unitOfWorkFactory.Create(TransactionMode.Default);
await _orderRepo.AddAsync(order);
unitOfWork.Commit();
}
}
Soft Delete
Entities implementing ISoftDelete get automatic repository behavior:
- Reads: A
!IsDeletedfilter is combined with your query expression automatically - Writes:
DeleteAsync(entity, isSoftDelete: true)setsIsDeleted = trueand performs an UPDATE instead of a DELETE
using RCommon.Entities;
public class Customer : BusinessEntity<int>, ISoftDelete
{
public string Name { get; set; }
public bool IsDeleted { get; set; }
}
// Queries automatically exclude soft-deleted records
var activeCustomers = await repo.FindAsync(c => c.Name.StartsWith("A"));
// Soft delete
await repo.DeleteAsync(customer, isSoftDelete: true);
// Physical delete
await repo.DeleteAsync(customer);
Multitenancy
Entities implementing IMultiTenant get automatic repository behavior:
- Reads: A
TenantId == currentTenantIdfilter is combined with your query expression automatically - Writes:
TenantIdis stamped on the entity duringAddAsyncusing the currentITenantIdAccessor
using RCommon.Entities;
public class Product : BusinessEntity<int>, IMultiTenant
{
public string Name { get; set; }
public string? TenantId { get; set; }
}
// Queries automatically scoped to the current tenant
var products = await repo.FindAsync(p => p.Name.Contains("Widget"));
// TenantId is stamped automatically on add
await repo.AddAsync(new Product { Name = "Widget" });
When no ITenantIdAccessor is configured (or it returns null), tenant filtering is bypassed entirely.
Key Types
| Type | Description |
|---|---|
IReadOnlyRepository<TEntity> |
Async read operations: find by key, expression, specification, count, and any |
IWriteOnlyRepository<TEntity> |
Async write operations: add, add range, update, delete, and delete many |
ILinqRepository<TEntity> |
Combines read/write with IQueryable<T> support, pagination, and eager loading |
IGraphRepository<TEntity> |
Extends ILinqRepository<T> with change tracking control for full ORMs |
ISqlMapperRepository<TEntity> |
Read/write repository for micro-ORMs with explicit table name mapping |
IUnitOfWork |
Transaction scope that commits or rolls back on dispose |
IUnitOfWorkFactory |
Creates IUnitOfWork instances with configurable transaction mode and isolation level |
IDataStoreFactory |
Resolves named data store instances (DbContext, DbConnection, etc.) |
IPersistenceBuilder |
Fluent builder interface for registering persistence providers in DI |
LinqRepositoryBase<TEntity> |
Abstract base class for LINQ-enabled repository implementations |
SqlRepositoryBase<TEntity> |
Abstract base class for SQL mapper repository implementations |
SoftDeleteHelper |
Utility for validating ISoftDelete support, marking entities deleted, and building !IsDeleted filter expressions |
MultiTenantHelper |
Utility for validating IMultiTenant support, stamping TenantId, and building tenant filter expressions |
Documentation
For full documentation, visit rcommon.com.
Related Packages
- RCommon.EFCore - Entity Framework Core implementation
- RCommon.Dapper - Dapper implementation
- RCommon.Linq2Db - Linq2Db implementation
License
Licensed under the Apache License, Version 2.0.
| 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 is compatible. 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 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
- RCommon.Core (>= 2.4.1)
- RCommon.Entities (>= 2.4.1)
- RCommon.Security (>= 2.4.1)
-
net8.0
- RCommon.Core (>= 2.4.1)
- RCommon.Entities (>= 2.4.1)
- RCommon.Security (>= 2.4.1)
-
net9.0
- RCommon.Core (>= 2.4.1)
- RCommon.Entities (>= 2.4.1)
- RCommon.Security (>= 2.4.1)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on RCommon.Persistence:
| Package | Downloads |
|---|---|
|
RCommon.Persistence.EFCore
A cohesive set of .NET 7 infrastructure libraries that utilizes abstractions for persistence, unit of work/transactions, distributed events, distributed transactions, and more. |
|
|
RCommon.BusinessServices
A lightweight application framework that utilizes abstractions over commonly used patterns to future proof applications. |
|
|
RCommon.Persistence.NHibernate
A cohesive set of .NET 6 infrastructure libraries that utilizes abstractions for persistence, unit of work/transactions, distributed events, distributed transactions, and more. |
|
|
RCommon.Persistence.Dapper
A cohesive set of .NET 7 infrastructure libraries that utilizes abstractions for persistence, unit of work/transactions, distributed events, distributed transactions, and more. |
|
|
RCommon.EFCore
A cohesive set of infrastructure libraries for dotnet that utilizes abstractions for event handling, persistence, unit of work, mediator, distributed messaging, event bus, CQRS, email, and more |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.4.1 | 0 | 2/18/2026 |
| 2.3.2-alpha.0.3 | 0 | 2/18/2026 |
| 2.3.2-alpha.0.2 | 0 | 2/18/2026 |
| 2.3.2-alpha.0.1 | 48 | 2/9/2026 |
| 2.3.1 | 212 | 2/5/2026 |
| 2.3.0 | 198 | 2/3/2026 |
| 2.2.2-alpha.0.1 | 392 | 12/11/2025 |
| 2.2.1-alpha.0.2 | 126 | 10/24/2025 |
| 2.2.1-alpha.0.1 | 144 | 10/24/2025 |
| 2.1.11-alpha.0.2 | 129 | 10/24/2025 |
| 2.1.11-alpha.0.1 | 98 | 7/18/2025 |
| 2.1.10 | 414 | 7/17/2025 |
| 2.1.9-alpha.0.1 | 148 | 7/17/2025 |
| 2.1.2.4 | 383 | 5/21/2025 |
| 2.1.2.3 | 373 | 5/1/2025 |
| 2.1.2.2 | 703 | 1/23/2025 |
| 2.1.2.1 | 339 | 1/17/2025 |
| 2.1.2 | 319 | 1/17/2025 |
| 2.1.1.4 | 338 | 1/7/2025 |
| 0.0.0-alpha.0 | 148 | 7/17/2025 |