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
<PackageReference Include="Net4x.DapperLibrary.SqlServer" Version="1.9.9" />
<PackageVersion Include="Net4x.DapperLibrary.SqlServer" Version="1.9.9" />
<PackageReference Include="Net4x.DapperLibrary.SqlServer" />
paket add Net4x.DapperLibrary.SqlServer --version 1.9.9
#r "nuget: Net4x.DapperLibrary.SqlServer, 1.9.9"
#:package Net4x.DapperLibrary.SqlServer@1.9.9
#addin nuget:?package=Net4x.DapperLibrary.SqlServer&version=1.9.9
#tool nuget:?package=Net4x.DapperLibrary.SqlServer&version=1.9.9
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
SqlDapperContextthat wires SQL Server-specific defaults intoDapperContext. - A
SqlProviderFactorythat configures data adapter behavior, parameter handling and row update events. SqlDatabaseModelwith SQL Server delimiters, parameter prefix and type mappings.- Helpers for administrative tasks (for example
RestoreDatabaseFromBackupAsync).
Key types
SqlDapperContext� derivedDapperContextconfigured for SQL Server. Convenience staticUse/UseOncemethods register aContextCreatorthat sets SQL Server defaults (for instanceIdentityInitializerandFormatDatetimeAsString). Constructors acceptDapperConnectionStringSettingsorIConfiguration.SqlProviderFactory� provider factory based on the underlying SQL client factory (System.Data.SqlClienton older frameworks orMicrosoft.Data.SqlClienton newer). It setsParameterModel.AddIndex = trueand installs aPrepareCommandParametersdelegate. It also exposes row-updating/updated event raising hooks.SqlDatabaseModel� implementsDatabaseModelspecifics for SQL Server (begin/end delimiters[/], batch separatorGO, parameter prefix@, and SQL Server-specific type mappings).RestoreExtension� utility extension providingRestoreDatabaseFromBackupAsyncwhich 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 usesSystem.Data.SqlClient. - On newer targets the project uses
Microsoft.Data.SqlClient.
- On older targets (
- NuGet artifacts produced from this source will include framework-specific assemblies and the appropriate SQL client dependency for each target.
Synchronous vs asynchronous behavior
SqlDapperContextand the underlyingDapperContextexpose both synchronous and asynchronous operations. Use theAsync-suffixed methods for non-blocking I/O (for exampleGetDataReaderAsync,SetDataAsync,GetDataTableAsync).RestoreDatabaseFromBackupAsyncis 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 certainCloseAsyncorReadAsyncAPIs.
Events and adapters
SqlProviderFactory.CreateDataAdapterattaches toRowUpdated/RowUpdatingevents and forwards them via the provider factory's raised events. This allows consumer code to react to row update lifecycle events when usingDbDataAdapteroperations (for example when usingSaveDataTable).
Notes and best practices
- Prefer the
Use/UseOncestatic 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 | Versions 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. |
-
.NETFramework 3.5
- Net4x.DapperLibrary.Base (>= 1.9.9)
-
.NETFramework 4.0
- Net4x.DapperLibrary.Base (>= 1.9.9)
-
.NETFramework 4.5
- Net4x.DapperLibrary.Base (>= 1.9.9)
-
.NETFramework 4.6.1
- Azure.Identity (>= 1.13.1)
- Microsoft.Data.SqlClient (>= 5.2.1)
- Net4x.DapperLibrary.Base (>= 1.9.9)
- System.Data.SqlClient (>= 4.8.6)
-
.NETStandard 2.0
- Azure.Identity (>= 1.13.1)
- Microsoft.Data.SqlClient (>= 5.2.1)
- Net4x.DapperLibrary.Base (>= 1.9.9)
- System.Configuration.ConfigurationManager (>= 9.0.0)
- System.Data.SqlClient (>= 4.8.6)
-
.NETStandard 2.1
- Azure.Identity (>= 1.13.1)
- Microsoft.Data.SqlClient (>= 5.2.1)
- Net4x.DapperLibrary.Base (>= 1.9.9)
- System.Configuration.ConfigurationManager (>= 9.0.0)
- System.Data.SqlClient (>= 4.8.6)
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 |