RCommon.Dapper
2.4.1
dotnet add package RCommon.Dapper --version 2.4.1
NuGet\Install-Package RCommon.Dapper -Version 2.4.1
<PackageReference Include="RCommon.Dapper" Version="2.4.1" />
<PackageVersion Include="RCommon.Dapper" Version="2.4.1" />
<PackageReference Include="RCommon.Dapper" />
paket add RCommon.Dapper --version 2.4.1
#r "nuget: RCommon.Dapper, 2.4.1"
#:package RCommon.Dapper@2.4.1
#addin nuget:?package=RCommon.Dapper&version=2.4.1
#tool nuget:?package=RCommon.Dapper&version=2.4.1
RCommon.Dapper
Dapper implementation of the RCommon persistence abstractions. Provides a lightweight SQL mapper repository using Dapper and Dommel for CRUD operations with expression-based querying, while integrating with the RCommon data store factory and domain event tracking.
Features
DapperRepository<TEntity>implementingISqlMapperRepository<T>,IReadOnlyRepository<T>, andIWriteOnlyRepository<T>- Expression-based querying via Dommel's
SelectAsync,CountAsync, andAnyAsyncextension methods - CRUD operations mapped to SQL using Dommel's
InsertAsync,UpdateAsync, andDeleteAsync - Bulk delete support via
DeleteMultipleAsyncwith expression predicates - Find by primary key using Dommel's
GetAsync - Automatic connection lifecycle management (open/close per operation)
- Named data store support for multi-database scenarios through
IDataStoreFactoryandRDbConnection - Fluent DI configuration to register database connections as named data stores
- Domain event tracking integrated into add, update, and delete operations
- Soft delete -- entities implementing
ISoftDeleteare automatically filtered on reads and logically deleted on writes - Multitenancy -- entities implementing
IMultiTenantare automatically filtered by tenant on reads and stamped withTenantIdon writes - Targets .NET 8, .NET 9, and .NET 10
Installation
dotnet add package RCommon.Dapper
Usage
// Configure in Program.cs or Startup
builder.Services.AddRCommon()
.WithPersistence<DapperPersistenceBuilder>(dapper =>
{
dapper.AddDbConnection<ApplicationDbConnection>("ApplicationDb", options =>
{
options.DbFactory = SqlClientFactory.Instance;
options.ConnectionString = builder.Configuration.GetConnectionString("ApplicationDb");
});
dapper.SetDefaultDataStore(defaults =>
defaults.DefaultDataStoreName = "ApplicationDb");
});
Your database connection must inherit from RDbConnection:
public class ApplicationDbConnection : RDbConnection
{
public ApplicationDbConnection(IOptions<RDbConnectionOptions> options)
: base(options) { }
}
Then inject and use the repository abstractions:
public class ProductService
{
private readonly ISqlMapperRepository<Product> _productRepo;
public ProductService(ISqlMapperRepository<Product> productRepo)
{
_productRepo = productRepo;
}
public async Task<ICollection<Product>> GetActiveProductsAsync()
{
return await _productRepo.FindAsync(p => p.IsActive);
}
public async Task<Product> GetByIdAsync(int id)
{
return await _productRepo.FindAsync(id);
}
}
Soft Delete and Multitenancy
DapperRepository<TEntity> automatically supports soft delete and multitenancy when your entities implement the opt-in interfaces:
using RCommon.Entities;
public class Product : BusinessEntity<int>, ISoftDelete, IMultiTenant
{
public string Name { get; set; }
public bool IsDeleted { get; set; }
public string? TenantId { get; set; }
}
Reads automatically exclude soft-deleted records and scope to the current tenant:
// Both filters applied transparently
var products = await _productRepo.FindAsync(p => p.IsActive);
Writes automatically stamp the tenant and support logical deletion:
// TenantId stamped automatically from ITenantIdAccessor
await _productRepo.AddAsync(new Product { Name = "Widget" });
// Soft delete — sets IsDeleted = true, performs UPDATE via Dapper
await _productRepo.DeleteAsync(product, isSoftDelete: true);
Key Types
| Type | Description |
|---|---|
DapperRepository<TEntity> |
Concrete repository using Dapper/Dommel with expression-based CRUD operations |
DapperPersistenceBuilder |
Fluent builder for registering Dapper database connections and repository services in DI |
IDapperBuilder |
Builder interface exposing AddDbConnection<T>() for registering named database connections |
Documentation
For full documentation, visit rcommon.com.
Related Packages
- RCommon.Persistence - Core persistence abstractions (required dependency)
- RCommon.EFCore - Entity Framework Core 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
- Dapper (>= 2.1.66)
- Dommel (>= 3.5.1)
- RCommon.Core (>= 2.4.1)
- RCommon.Persistence (>= 2.4.1)
-
net8.0
- Dapper (>= 2.1.66)
- Dommel (>= 3.5.1)
- RCommon.Core (>= 2.4.1)
- RCommon.Persistence (>= 2.4.1)
-
net9.0
- Dapper (>= 2.1.66)
- Dommel (>= 3.5.1)
- RCommon.Core (>= 2.4.1)
- RCommon.Persistence (>= 2.4.1)
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.4.1 | 34 | 2/18/2026 |
| 2.3.2-alpha.0.3 | 33 | 2/18/2026 |
| 2.3.2-alpha.0.2 | 28 | 2/18/2026 |
| 2.3.2-alpha.0.1 | 41 | 2/9/2026 |
| 2.3.1 | 94 | 2/5/2026 |
| 2.3.0 | 82 | 2/3/2026 |
| 2.2.2-alpha.0.1 | 385 | 12/11/2025 |
| 2.2.1-alpha.0.2 | 137 | 10/24/2025 |
| 2.2.1-alpha.0.1 | 139 | 10/24/2025 |
| 2.1.11-alpha.0.2 | 124 | 10/24/2025 |
| 2.1.11-alpha.0.1 | 98 | 7/18/2025 |
| 2.1.10 | 276 | 7/17/2025 |
| 2.1.9-alpha.0.1 | 143 | 7/17/2025 |
| 2.1.2.4 | 219 | 5/21/2025 |
| 2.1.2.3 | 203 | 5/1/2025 |
| 2.1.2.2 | 298 | 1/23/2025 |
| 2.1.2.1 | 149 | 1/17/2025 |
| 2.1.2 | 151 | 1/17/2025 |
| 2.1.1.4 | 170 | 1/7/2025 |
| 0.0.0-alpha.0 | 142 | 7/17/2025 |