Net4x.DapperLibrary.SqlServer 1.9.9

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

DapperLibrary.SqlServer

SQL Server provider-specific extensions for DapperLibrary. This project contains the SQL Server concrete SqlDapperContext, the SqlProviderFactory and SQL Server specific database model types and helpers such as restore-from-backup extensions.

Purpose

Provide SQL Server engine-specific behavior and defaults while keeping the DapperLibrary public API consistent across providers. This includes:

  • A SqlDapperContext that wires SQL Server-specific defaults into DapperContext.
  • A SqlProviderFactory that configures data adapter behavior, parameter handling and row update events.
  • SqlDatabaseModel with SQL Server delimiters, parameter prefix and type mappings.
  • Helpers for administrative tasks (for example RestoreDatabaseFromBackupAsync).

Key types

  • SqlDapperContext � derived DapperContext configured for SQL Server. Convenience static Use / UseOnce methods register a ContextCreator that sets SQL Server defaults (for instance IdentityInitializer and FormatDatetimeAsString). Constructors accept DapperConnectionStringSettings or IConfiguration.

  • SqlProviderFactory � provider factory based on the underlying SQL client factory (System.Data.SqlClient on older frameworks or Microsoft.Data.SqlClient on newer). It sets ParameterModel.AddIndex = true and installs a PrepareCommandParameters delegate. It also exposes row-updating/updated event raising hooks.

  • SqlDatabaseModel � implements DatabaseModel specifics for SQL Server (begin/end delimiters [ / ], batch separator GO, parameter prefix @, and SQL Server-specific type mappings).

  • RestoreExtension � utility extension providing RestoreDatabaseFromBackupAsync which reads backup logical names, computes file move clauses and executes a restore statement. It demonstrates safe closing of open readers and connections and updates the context's active connection string to point at the restored database.

Usage

Create and use a SqlDapperContext as you would a DapperContext, or use the static helpers to wire convenient context creation:

// Simple: create from defaults
using var context = new SqlDapperContext();

// Register usage factory in bootstrap code
SqlDapperContext.Use();

// Use a single use creator with explicit connection string
SqlDapperContext.UseOnce(connectionString, providerName);

Customize identity and datetime formatting when using the static helpers (these are set automatically by the Use helpers):

// The created context will have: DatabaseModel.IdentityInitializer = "IDENTITY(int, 1, 1)"
// and a FormatDatetimeAsString that produces CONVERT(datetime, '...') SQL compatible with SQL Server.

Restore database example:

await context.RestoreDatabaseFromBackupAsync("MyNewDb", @"C:\Backups\mydb.bak");

Restore will close any open readers and connections used by the DapperContext and update the context's ConnectionStringSettings to point to the restored database.

Multi-targeting & client compatibility

  • The code contains conditional compilation to support older .NET Framework targets and modern .NET runtimes. The SQL client implementation chosen depends on the target framework:
    • On older targets (NET35, NET40, NET45, NET461, etc.) the project uses System.Data.SqlClient.
    • On newer targets the project uses Microsoft.Data.SqlClient.
  • NuGet artifacts produced from this source will include framework-specific assemblies and the appropriate SQL client dependency for each target.

Synchronous vs asynchronous behavior

  • SqlDapperContext and the underlying DapperContext expose both synchronous and asynchronous operations. Use the Async-suffixed methods for non-blocking I/O (for example GetDataReaderAsync, SetDataAsync, GetDataTableAsync).
  • RestoreDatabaseFromBackupAsync is implemented as an async operation and uses async reader/close patterns where available; conditional compilation guards are present to handle frameworks that do not expose certain CloseAsync or ReadAsync APIs.

Events and adapters

  • SqlProviderFactory.CreateDataAdapter attaches to RowUpdated/RowUpdating events and forwards them via the provider factory's raised events. This allows consumer code to react to row update lifecycle events when using DbDataAdapter operations (for example when using SaveDataTable).

Notes and best practices

  • Prefer the Use / UseOnce static helpers when wiring SQL Server contexts�these helpers preconfigure common SQL Server behaviors.
  • When running restore or other administrative operations, ensure the process has sufficient permissions and that no external process is locking the target files.
  • Use async APIs in server applications to avoid blocking thread-pool threads.

For further details consult the source files in DbContexts and Extensions directories.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net35 is compatible.  net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on Net4x.DapperLibrary.SqlServer:

Package Downloads
Net4x.DapperLibrary.MockSqlServer

Package Description

Net4x.Xsd2Db.Data

Package Description

Net4x.EntityFramework.Library

Package Description

Net4x.DapperLibrary.Docker

Package Description

Net4x.Xsd2Db.Base

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.9.9 25 12/22/2025
1.6.0.12 243 12/12/2025
1.6.0.11 229 12/12/2025
1.6.0.10 534 12/9/2025
1.6.0.9 212 12/4/2025
1.6.0.8 215 12/4/2025
1.6.0.7 277 11/30/2025
1.6.0.6 201 11/27/2025
1.6.0.5 268 11/22/2025
1.6.0.4 165 11/16/2025
1.6.0.3 202 11/15/2025
1.6.0.2 336 11/14/2025
1.6.0.1 261 11/10/2025
1.6.0 228 11/9/2025
1.5.0.3 223 11/5/2025
1.5.0.2 223 11/3/2025
1.5.0.1 222 11/3/2025
1.5.0 184 10/26/2025
1.4.1.6 227 10/24/2025
1.4.1.5 212 10/22/2025
1.4.1.4 231 10/22/2025
1.4.1.2 249 5/30/2025
1.4.1.1 235 4/30/2025
1.4.1 232 4/30/2025
1.4.0 490 3/31/2025
1.1.0 1,184 8/26/2023
1.1.0-at20230506041136 834 5/7/2023