NTDLS.SqlServerDapperWrapper
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NTDLS.SqlServerDapperWrapper --version 1.0.1
NuGet\Install-Package NTDLS.SqlServerDapperWrapper -Version 1.0.1
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="NTDLS.SqlServerDapperWrapper" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NTDLS.SqlServerDapperWrapper --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NTDLS.SqlServerDapperWrapper, 1.0.1"
#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.
// Install NTDLS.SqlServerDapperWrapper as a Cake Addin #addin nuget:?package=NTDLS.SqlServerDapperWrapper&version=1.0.1 // Install NTDLS.SqlServerDapperWrapper as a Cake Tool #tool nuget:?package=NTDLS.SqlServerDapperWrapper&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NTDLS.SqlServerDapperWrapper
📦 Be sure to check out the NuGet package: https://www.nuget.org/packages/NTDLS.SqlServerDapperWrapper
Provides a simple interface to a SQL Server database with automatic cleanup and stored procedure detection. All managed and wrapped in Dapper (hence the name).
Examples:
public static ManagedDataStorageFactory MyConnection { get; set; } = new("localhost", "tempdb");
//Each time a statement/query is executed, the NTDLS.SqlServerDapperWrapper will
// open a connection, execute then close & dispose the connection.
MyConnection.Execute("DROP TABLE IF EXISTS Test");
//Creates a table in two different databases from a script that is an embedded resource in the project.
MyConnection.Execute("CREATE TABLE Test( Id int identity(1,1) not null, [Name] varchar(128) NOT NULL, [Description] varchar(128) NULL)");
//Deletes the data from the table "Test".
MyConnection.Execute("DELETE FROM Test");
//Insert some records using an inline statement and parameters.
for (int i = 0; i < 100; i++)
{
var param = new
{
Name = $"Name #{i}",
Description = Guid.NewGuid().ToString()
};
MyConnection.Execute("INSERT INTO Test (Name, Description) VALUES (@Name, @Description)", param);
}
//We can use "Ephemeral" to perform multiple steps on the same connection, such as here where we
// begin a transaction, insert data and then optionally commit or rollback the transaction.
// The connection is closed and disposed after Ephemeral() executes.
MyConnection.Ephemeral(o =>
{
using var tx = o.BeginTransaction();
try
{
for (int i = 0; i < 100; i++)
{
var param = new
{
Name = $"Name #{i}",
Description = Guid.NewGuid().ToString()
};
o.Execute("INSERT INTO Test (Name, Description) VALUES (@Name, @Description)", param);
}
tx.Commit();
}
catch
{
tx.Rollback();
throw;
}
});
//Just getting the results and writing them to the console.
var results = MyConnection.Query<TestModel>("SELECT * FROM Test");
//Print the results.
foreach (var result in results)
{
Console.WriteLine($"{result.Id} {result.Name} {result.Description}");
}
}
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Dapper (>= 2.1.35)
- Microsoft.Data.SqlClient (>= 5.2.1)
-
net7.0
- Dapper (>= 2.1.35)
- Microsoft.Data.SqlClient (>= 5.2.1)
-
net8.0
- Dapper (>= 2.1.35)
- Microsoft.Data.SqlClient (>= 5.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Readme fix.