LeanDb.Dapper
0.1.3
dotnet add package LeanDb.Dapper --version 0.1.3
NuGet\Install-Package LeanDb.Dapper -Version 0.1.3
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="LeanDb.Dapper" Version="0.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LeanDb.Dapper" Version="0.1.3" />
<PackageReference Include="LeanDb.Dapper" />
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 LeanDb.Dapper --version 0.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LeanDb.Dapper, 0.1.3"
#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 LeanDb.Dapper@0.1.3
#: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=LeanDb.Dapper&version=0.1.3
#tool nuget:?package=LeanDb.Dapper&version=0.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LeanDb.Dapper
Dapper-based query implementation for LeanDb. Use this package to execute LeanDb queries against any database with a Dapper-compatible IDbConnection.
Usage
// Define a query
public record GetUserCount : IQuery<int>;
// Define its Dapper implementation
public class GetUserCountImplementation : IDapperQueryImplementation<IDbConnection, int>
{
public GetUserCountImplementation(GetUserCount _) { }
public Task<int> Execute(IDbConnection connection, CancellationToken cancellationToken)
=> connection.QuerySingleAsync<int>("SELECT COUNT(*) FROM Users", cancellationToken);
}
// Register with DI
services.AddDapperDb<IDbConnection>(options =>
options.LoadImplementationsFromAssembly(typeof(GetUserCountImplementation)));
// Execute
var db = serviceProvider.GetRequiredService<DapperDb<IDbConnection>>();
var count = await db.Execute(new GetUserCount());
How it works
- Define a query — create a record or class implementing
IQuery<TResult>. - Implement the query — create a class implementing
IDapperQueryImplementation<TDbConnection, TResult>. The implementation receives the typed connection and executes the query using Dapper methods. - Register — call
AddDapperDb<TDbConnection>()on yourIServiceCollection, pointing to the assembly that contains your implementations. - Execute — resolve
DapperDb<TDbConnection>and callExecute(query).
Registration
services.AddDapperDb<TDbConnection>(options =>
{
// Required: scan an assembly for query implementations
options.LoadImplementationsFromAssembly(typeof(SomeImplementation));
// Optional: scan additional assemblies
options.LoadImplementationsFromAssembly(typeof(OtherImplementation));
});
The DapperDb<TDbConnection> is registered as scoped. Ensure the underlying TDbConnection is also registered with the desired lifetime in your DI container.
Requirements
- .NET 10 or later
Dapper2.1.66 or laterMicrosoft.Extensions.DependencyInjection.AbstractionsLeanDbandLeanDb.ImplementationAbstractions
Related packages
| Package | Description |
|---|---|
| LeanDb | Core abstractions — define queries in your domain layer |
| LeanDb.ImplementationAbstractions | Helper base types for building custom implementations |
| LeanDb.EntityFrameworkCore | Alternative EF Core-based query implementation |
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Dapper (>= 2.1.79)
- LeanDb (>= 0.1.3)
- LeanDb.ImplementationAbstractions (>= 0.1.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.