NPv.DataAccess.Dapper.Executor
1.0.3
dotnet add package NPv.DataAccess.Dapper.Executor --version 1.0.3
NuGet\Install-Package NPv.DataAccess.Dapper.Executor -Version 1.0.3
<PackageReference Include="NPv.DataAccess.Dapper.Executor" Version="1.0.3" />
<PackageVersion Include="NPv.DataAccess.Dapper.Executor" Version="1.0.3" />
<PackageReference Include="NPv.DataAccess.Dapper.Executor" />
paket add NPv.DataAccess.Dapper.Executor --version 1.0.3
#r "nuget: NPv.DataAccess.Dapper.Executor, 1.0.3"
#:package NPv.DataAccess.Dapper.Executor@1.0.3
#addin nuget:?package=NPv.DataAccess.Dapper.Executor&version=1.0.3
#tool nuget:?package=NPv.DataAccess.Dapper.Executor&version=1.0.3
NPv.DataAccess.Dapper.Executor
Dapper-based implementation of the ISqlExecutor
interface from NPv.DataAccess.Abstractions
.
Provides simple, consistent access to raw SQL queries without manual connection handling.
β¨ Overview
This library offers a lightweight executor for raw SQL queries and commands using Dapper and SqlClient.
It is designed to:
- Minimize boilerplate code (no using SqlConnection on every query)
- Standardize SQL access behind the
ISqlExecutor
abstraction - Fit cleanly into DI, CQRS, and layered architectures
π§ Features
- Executes raw SQL queries (
SELECT
,INSERT
,UPDATE
,DELETE
) - Wraps common Dapper methods:
--
QueryFirstAsync
--QueryFirstOrDefaultAsync
--QuerySingleAsync
--QuerySingleOrDefaultAsync
--QueryAsync
--ExecuteAsync
- Manages connection lifecycle internally
- Uses connection string from IConfiguration ("Default" key expected)
π§© Example Usage
public class GetProductByIdHandler(ISqlExecutor sql) : IQueryHandler<Guid, ProductDto?>
{
public async Task<ProductDto?> HandleAsync(Guid id)
{
const string sqlQuery = "SELECT Id, Name, Price FROM Products WHERE Id = @id";
return await sql.QueryFirstOrDefaultAsync<ProductDto>(sqlQuery, new { id });
}
}
π¦ Installation
This package is part of the NPv.Foundation.Net
architecture.
To install via NuGet:
dotnet add package NPv.DataAccess.Dapper.Executor
π οΈ Setup in DI
In your startup configuration:
services.AddScoped<ISqlExecutor, DapperSqlExecutor>();
Make sure your appsettings.json
contains a valid connection string:
{
"ConnectionStrings": {
"Default": "Server=...;Database=...;User Id=...;Password=...;"
}
}
π Related Packages
NPv.DataAccess.Abstractions
β Interface definition (ISqlExecutor
) --NPv.DataAccess.Ef
β EF Core implementation ofIGenericRepository
π Project Structure
NPv.DataAccess.Dapper.Executor
βββ DapperSqlExecutor.cs
βββ ISqlExecutor (from Abstractions)
Author's Note
This library grew out of my long-standing personal interest in structuring and publishing open source packages. Over time, Iβve revisited and refined earlier internal utilities and ideas, giving them a more consistent shape and preparing them for wider reuse. Along the way, Iβve also taken the opportunity to explore how open source distribution and licensing work in the .NET ecosystem.
Itβs a small step toward something Iβve always wanted to try β sharing practical, minimal tools that reflect years of learning, experimentation, and refinement.
Hopefully, someone finds it useful.
Nikolai π
βοΈ License
MIT β you are free to use this in commercial and open-source software.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
-
net9.0
- Dapper (>= 2.1.66)
- Microsoft.Data.SqlClient (>= 6.1.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.8)
- NPv.DataAccess.Abstractions (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.