StringThing.Npgsql.Dapper 1.0.0

dotnet add package StringThing.Npgsql.Dapper --version 1.0.0
                    
NuGet\Install-Package StringThing.Npgsql.Dapper -Version 1.0.0
                    
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="StringThing.Npgsql.Dapper" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StringThing.Npgsql.Dapper" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="StringThing.Npgsql.Dapper" />
                    
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 StringThing.Npgsql.Dapper --version 1.0.0
                    
#r "nuget: StringThing.Npgsql.Dapper, 1.0.0"
                    
#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 StringThing.Npgsql.Dapper@1.0.0
                    
#: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=StringThing.Npgsql.Dapper&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=StringThing.Npgsql.Dapper&version=1.0.0
                    
Install as a Cake Tool

StringThing.Npgsql.Dapper

Dapper result mapping for StringThing.Npgsql. Injection-safe interpolated SQL on the input side, Dapper mapping on the output side.

Install

dotnet add package StringThing.Npgsql.Dapper

Quick start

var userId = 42;
var user = await connection.QueryStringSingleAsync<User>(
    $"SELECT id, name, email FROM users WHERE id = {userId}",
    cancellationToken);

Available methods

All methods are extension methods on NpgsqlConnection:

Method Returns
QueryStringAsync<T> Task<List<T>>
QueryStringFirstAsync<T> Task<T>
QueryStringFirstOrDefaultAsync<T> Task<T?>
QueryStringSingleAsync<T> Task<T>
QueryStringSingleOrDefaultAsync<T> Task<T?>
ExecuteStringAsync Task<int>
ExecuteStringScalarAsync<T> Task<T?>

Synchronous variants are also available (without the Async suffix).

Why "String" in the method names?

The method names include String to avoid collision with Dapper's own extension methods. If both were named QueryAsync, a using change could silently switch from the safe StringThing path to Dapper's string-based path — defeating the injection safety guarantee.

QueryStringSingleAsync is unambiguous: it's the StringThing version, always.

DDL and static SQL

For setup queries with no parameters, use $"..." without interpolation:

await connection.ExecuteStringAsync(
    $"""
    CREATE TABLE IF NOT EXISTS users (
        id integer PRIMARY KEY,
        name text NOT NULL
    )
    """,
    cancellationToken);

Dapper license

This package bundles Dapper internally for result mapping. Dapper is licensed under the Apache License 2.0, copyright 2019 Stack Exchange, Inc. The bundled Dapper DLL is not exposed as a dependency — consumers do not need a separate Dapper reference.


Built by Immersus Machina

Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.