Transformations.Dapper
3.1.0
dotnet add package Transformations.Dapper --version 3.1.0
NuGet\Install-Package Transformations.Dapper -Version 3.1.0
<PackageReference Include="Transformations.Dapper" Version="3.1.0" />
<PackageVersion Include="Transformations.Dapper" Version="3.1.0" />
<PackageReference Include="Transformations.Dapper" />
paket add Transformations.Dapper --version 3.1.0
#r "nuget: Transformations.Dapper, 3.1.0"
#:package Transformations.Dapper@3.1.0
#addin nuget:?package=Transformations.Dapper&version=3.1.0
#tool nuget:?package=Transformations.Dapper&version=3.1.0
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.
📖 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.1.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.CoreDapperMicrosoft.Data.SqlClient
License
PolyForm Strict 1.0.0 — Copyright © 2026 opentail.net
| Product | Versions 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. |
-
net10.0
- Dapper (>= 2.1.89)
- Microsoft.Data.SqlClient (>= 7.1.1)
- System.Security.Cryptography.Pkcs (>= 9.0.21)
- Transformations.Core (>= 3.1.0)
- Transformations.Sql (>= 3.1.0)
-
net8.0
- Dapper (>= 2.1.89)
- Microsoft.Data.SqlClient (>= 7.1.1)
- System.Security.Cryptography.Pkcs (>= 8.0.2)
- Transformations.Core (>= 3.1.0)
- Transformations.Sql (>= 3.1.0)
-
net9.0
- Dapper (>= 2.1.89)
- Microsoft.Data.SqlClient (>= 7.1.1)
- System.Security.Cryptography.Pkcs (>= 9.0.21)
- Transformations.Core (>= 3.1.0)
- Transformations.Sql (>= 3.1.0)
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.