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
                    
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="NPv.DataAccess.Dapper.Executor" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NPv.DataAccess.Dapper.Executor" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="NPv.DataAccess.Dapper.Executor" />
                    
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 NPv.DataAccess.Dapper.Executor --version 1.0.3
                    
#r "nuget: NPv.DataAccess.Dapper.Executor, 1.0.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 NPv.DataAccess.Dapper.Executor@1.0.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=NPv.DataAccess.Dapper.Executor&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=NPv.DataAccess.Dapper.Executor&version=1.0.3
                    
Install as a Cake Tool

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=...;"
  }
}

  • NPv.DataAccess.Abstractions β€” Interface definition (ISqlExecutor) -- NPv.DataAccess.Ef β€” EF Core implementation of IGenericRepository

πŸ“ 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.3 134 8/18/2025
1.0.2 182 8/8/2025
1.0.1 123 6/15/2025
1.0.0 136 6/14/2025