Tagovi.DbConnectionWrapper
0.1.6
dotnet add package Tagovi.DbConnectionWrapper --version 0.1.6
NuGet\Install-Package Tagovi.DbConnectionWrapper -Version 0.1.6
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="Tagovi.DbConnectionWrapper" Version="0.1.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tagovi.DbConnectionWrapper" Version="0.1.6" />
<PackageReference Include="Tagovi.DbConnectionWrapper" />
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 Tagovi.DbConnectionWrapper --version 0.1.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tagovi.DbConnectionWrapper, 0.1.6"
#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 Tagovi.DbConnectionWrapper@0.1.6
#: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=Tagovi.DbConnectionWrapper&version=0.1.6
#tool nuget:?package=Tagovi.DbConnectionWrapper&version=0.1.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DbConnectionWrapper
A simple wrapper for IDbConnection that allows logging SQL statements and works easily with Dapper or anything where you can pass the IDbConnection you want to use.
It has support for Stored Procedures, Functions, and Table-Valued Functions and formats the logs such that they can be directly run in SSMS which is extremely useful for debugging.
All the code is in the DbConnectionWrapper.cs class, but I'm working on adding a Nuget package.
Usage
// #r "nuget: Dapper"
// #r "nuget: Microsoft.Data.SqlClient"
using var conn = new WrappedDbConnection(
new SqlConnection(@"Server=.\SqlExpress;Database=BogusLocal;Integrated Security=SSPI;TrustServerCertificate=True;"),
x => new ActionDbCommand(x, Console.WriteLine)
);
// Example: int
var result = conn.Query("SELECT * FROM Table WHERE Id=@id", new
{
Id = 1,
});
/*
DECLARE @Id Int = '1'
SELECT * FROM Table WHERE Id=@id
*/
// Example: string
var result = conn.Query("SELECT * FROM Table WHERE Name=@name", new
{
name = "github"
});
/*
DECLARE @name NVarChar(4000) = 'github'
SELECT * FROM Table WHERE Name=@name
*/
// Example: sql function
var result = conn.Query(@"SELECT dbo.SomeFunction(@Id, @Name)", new
{
Id = 1,
Name = (string?)null,
});
/*
DECLARE @Id Int = '1'
DECLARE @Name NVarChar(1) = NULL
SELECT dbo.SomeFunction(@Id, @Name)
*/
// Example: stored procedure
var result = conn.Query(@"EXEC StoredProc @Id", new
{
Id = 1,
});
/*
DECLARE @Id Int = '1'
EXEC StoredProc @Id
*/
// Example: table-valued function
var result = conn.Query(@"SELECT * FROM TableValuedFunction(@Id,@Date,@Format)", new
{
Id = 1,
Date = DateTime.Parse("2/1/2016"),
Format = "MMM-yy"
});
/*
DECLARE @Id Int = '1'
DECLARE @Date DateTime = '2/1/2016 12:00:00 AM'
DECLARE @Format NVarChar(4000) = 'MMM-yy'
SELECT * FROM TableValuedFunction(@Id,@Date,@Format)
*/
// Example: output parameters
var param = new DynamicParameters(new
{
InputId = 1,
});
param.Add("OutputId", dbType: DbType.Int32, direction: ParameterDirection.Output);
var result = conn.Query(@"EXEC StoredProc @InputId,@OutputId OUTPUT", param);
/*
DECLARE @InputId Int = '1'
DECLARE @OutputId Int = NULL
EXEC StoredProc @InputId,@OutputId OUTPUT
SELECT @RunId AS [RunId]
*/
// Example: return value
var param = new DynamicParameters();
param.Add("Return", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
conn.Execute(@"Proc", param, commandType: CommandType.StoredProcedure);
var result = param.Get<int>("Return");
/*
DECLARE @Return Int = NULL
EXEC @Return = Proc
SELECT @Return AS [Return]
*/
| 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.Data.SqlClient (>= 4.1.0)
- System.Data.Common (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.