Transformations.Dapper 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Transformations.Dapper --version 3.0.0
                    
NuGet\Install-Package Transformations.Dapper -Version 3.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="Transformations.Dapper" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Transformations.Dapper" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Transformations.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 Transformations.Dapper --version 3.0.0
                    
#r "nuget: Transformations.Dapper, 3.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 Transformations.Dapper@3.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=Transformations.Dapper&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Transformations.Dapper&version=3.0.0
                    
Install as a Cake Tool

Transformations.Dapper

Resilient Dapper query wrappers with built-in transient SQL fault detection — drop-in replacements for standard Dapper methods that automatically retry on deadlocks, timeouts, and Azure SQL throttling.

NuGet .NET 8 | 9 | 10

📖 Overview

Transformations.Dapper brings the hardened retry semantics of Transformations.Core directly into your Dapper workflows. Cloud databases regularly drop connections or trigger transient deadlocks — this library automatically identifies retriable SQL error codes and re-executes queries transparently.

🚀 Why Transformations.Dapper?

Instead of manually catching SqlException and writing retry loops everywhere, you swap connection.QueryAsync for connection.QueryWithRetryAsync. The built-in transient fault detector handles the backoff strategy. The result is database code that's both cleaner and more resilient — with no extra ceremony.

📦 Install

<PackageReference Include="Transformations.Dapper" Version="3.0.0.0" />

💡 What's Included

Resilient Async Queries

Swap connection.QueryAsync for connection.QueryWithRetryAsync. Transient SQL faults are detected automatically and retried with exponential backoff.

// 3 retries, 500ms initial delay — doubles each attempt
var users = await connection.QueryWithRetryAsync<User>(
    "SELECT * FROM Users WHERE Status = @Status",
    new { Status = UserStatus.Active },
    retryCount: 3,
    initialDelay: TimeSpan.FromMilliseconds(500));

// Single row — returns null rather than throwing on no result
var user = await connection.QuerySingleOrDefaultWithRetryAsync<User>(
    "SELECT * FROM Users WHERE Id = @Id",
    new { Id = userId });

// Execute (INSERT/UPDATE/DELETE) and scalar
int affected = await connection.ExecuteWithRetryAsync(
    "DELETE FROM Sessions WHERE ExpiredAt < @Now", new { Now = DateTime.UtcNow });

int count = await connection.ExecuteScalarWithRetryAsync<int>(
    "SELECT COUNT(*) FROM Users WHERE Active = 1");

Transient Fault Detection

SqlTransientFaultDetector.IsTransient classifies SQL Server errors that are safe to retry, and TimeoutException. It lives in the Transformations.Sql package, which this package depends on, so import that namespace. The SQL Server error numbers are:

Group Error numbers
Connection and timeouts -2 (client timeout), 53 (cannot open a connection), 121 (semaphore timeout), 64 (connection dropped after it was established), 233 (connection initialisation), 921 (database not yet recovered), 17197 (login timeout), 14355 (busy service)
Locks and memory 1205 (deadlock victim), 1221 (lock request timeout), 1807 (exclusive lock on database), 8628 and 8645 (memory grant or resource timeout)
Transport 10053, 10054, 10060 (network errors while sending or receiving)
Azure SQL throttling and availability 10928, 10929, 10936, 40143, 40197, 40501, 40540, 40613, 49918, 49919, 49920
In-memory OLTP 41301, 41302, 41305, 41325, 41839

GetTransientErrorNumbers() returns the same set. A test pins that set, so changing the codes means updating the test and this table together. SQLite and other providers have no entries here, so their busy errors are not retried by these wrappers. Use it in your own catch blocks:

using Transformations.Sql;

catch (SqlException ex) when (SqlTransientFaultDetector.IsTransient(ex))
{
    logger.LogWarning(ex, "Transient SQL fault on attempt {Attempt}", attempt);
}
Migrating from Transformations.Dapper.SqlTransientFaultDetector

Earlier 3.x releases had the detector in this package's namespace. It is now [Obsolete] and forwards to Transformations.Sql.SqlTransientFaultDetector. The compiler reports CS0618 with that replacement. The forwarder will be removed in the next major version.

Change the using and keep the calls as they are:

// Before
using Transformations.Dapper;

// After
using Transformations.Sql;

If your file also imports Transformations.Dapper for the extension methods, the unqualified name is ambiguous (CS0104). Qualify the call instead:

catch (SqlException ex) when (Transformations.Sql.SqlTransientFaultDetector.IsTransient(ex))

SqlParameter Bridge

Converts anonymous or POCO objects to SqlParameter[] — useful when bridging legacy SqlCommand code or when you need explicit SqlDbType control that Dapper's anonymous parameters don't offer.

// From an anonymous object
IReadOnlyList<SqlParameter> sqlParams = SqlParameterBridge.ToSqlParameters(
    new { UserId = 42, Name = "Alice" });

// With explicit SqlDbType overrides
IReadOnlyList<SqlParameter> sqlParams = SqlParameterBridge.ToSqlParameters(
    new { UserId = 42, Bio = longText },
    new Dictionary<string, SqlDbType>
    {
        ["Bio"] = SqlDbType.NVarChar
    });

// NativeAOT / trimmer-safe generic overload
IReadOnlyList<SqlParameter> sqlParams = SqlParameterBridge.ToSqlParameters<MyParams>(myParams);

🛠 API Reference

Class Purpose Key Members
DapperResilienceExtensions Retry-wrapped Dapper QueryWithRetryAsync<T>, QuerySingleOrDefaultWithRetryAsync<T>, ExecuteWithRetryAsync, ExecuteScalarWithRetryAsync<T>
SqlTransientFaultDetector (in Transformations.Sql) SQL error classification IsTransient(Exception), GetTransientErrorNumbers()
SqlParameterBridge Object → SqlParameter[] ToSqlParameters(object), ToSqlParameters(object, typeMappings), ToSqlParameters<T>(T)

📦 Dependencies

  • Transformations.Core
  • Dapper
  • Microsoft.Data.SqlClient

License

PolyForm Strict 1.0.0 — Copyright © 2026 opentail.net

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

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Transformations.Dapper:

Package Downloads
Transformations

Modern .NET transformation helpers for conversion, strings, collections, data, web, diagnostics, batching, and resilience.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 24 10/27/2026
3.0.0 43 10/27/2026
2.0.5.1 82 10/23/2026
2.0.4.6 111 10/11/2026
2.0.4.5 120 10/10/2026
2.0.4.2 176 7/7/2026
2.0.4.1 167 7/7/2026
2.0.0 158 4/10/2026