JLOrdaz.DapperDataMSSQL
1.3.0
dotnet add package JLOrdaz.DapperDataMSSQL --version 1.3.0
NuGet\Install-Package JLOrdaz.DapperDataMSSQL -Version 1.3.0
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="JLOrdaz.DapperDataMSSQL" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JLOrdaz.DapperDataMSSQL" Version="1.3.0" />
<PackageReference Include="JLOrdaz.DapperDataMSSQL" />
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 JLOrdaz.DapperDataMSSQL --version 1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JLOrdaz.DapperDataMSSQL, 1.3.0"
#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 JLOrdaz.DapperDataMSSQL@1.3.0
#: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=JLOrdaz.DapperDataMSSQL&version=1.3.0
#tool nuget:?package=JLOrdaz.DapperDataMSSQL&version=1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JLOrdaz.DapperDataMSSQL
Lightweight helper to execute SQL Server stored procedures using Dapper and Microsoft.Data.SqlClient with a simple DI registration.
Install
dotnet add package JLOrdaz.DapperDataMSSQL
Configuration
Add your connection string in appsettings.json (or environment/config provider of your choice):
{
"ConnectionStrings": {
"DB": "Server=.;Database=MyDb;Trusted_Connection=True;TrustServerCertificate=True;"
}
}
Usage with Dependency Injection (recommended)
Register the library in your DI container and inject ISQLDataAccess where needed.
Program.cs (ASP.NET Core):
var builder = WebApplication.CreateBuilder(args);
// Option 1: Register using connection string name from configuration
builder.Services.AddDapperDataMSSQL(useConnectionStringName: true, connectionStringOrName: "DB");
// Option 2: Register using direct connection string
// builder.Services.AddDapperDataMSSQL(
// useConnectionStringName: false,
// connectionStringOrName: "Server=.;Database=MyDb;Trusted_Connection=True;TrustServerCertificate=True;"
// );
var app = builder.Build();
app.Run();
Parameters:
useConnectionStringName: Iftrue, looks up the connection string in configuration. Iffalse, uses the value directly as connection string.connectionStringOrName: The configuration key name (ifuseConnectionStringNameistrue) or the actual connection string (iffalse).
Example repository/service:
using JLOrdaz.DapperDataMSSQL;
public sealed class UserRepository
{
private readonly ISQLDataAccess _db;
public UserRepository(ISQLDataAccess db)
{
_db = db;
}
public Task<IEnumerable<User>> GetUsersAsync() =>
_db.LoadData<User, object>("dbo.Users_GetAll", new { });
public Task<User?> GetUserAsync(int id) =>
_db.LoadFirst<User, object>("dbo.Users_GetById", new { Id = id });
public Task SaveUserAsync(User user) =>
_db.SaveData("dbo.Users_Upsert", new { user.Id, user.Name });
}
// Example: stored procedure that returns two result sets (e.g., Users and Roles)
public Task ExampleLoadMultipleAsync(ISQLDataAccess db) =>
// Assumes stored procedure 'dbo.UsersAndRoles_Get' returns users in first result set and roles in second
// The new method returns a tuple with both enumerables
db.LoadMultiple<User, Role, object>("dbo.UsersAndRoles_Get", new { });
// Example: execute stored procedure that returns a scalar value (e.g., newly inserted identity)
public Task<int?> CreateUserAndGetIdAsync(ISQLDataAccess db, User user) =>
// Assumes stored procedure 'dbo.Users_Insert' inserts and returns the new Id as scalar
db.ExecuteScalarAsync<int, object>("dbo.Users_Insert", new { user.Name });
Notes:
- The connection string is configured once during service registration via
AddDapperDataMSSQL. storeProcedureis the stored procedure name (schema-qualified recommended).
Dependencies
- Microsoft.Data.SqlClient
- Dapper
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Dapper (>= 2.1.66)
- Microsoft.Data.SqlClient (>= 6.1.4)
- Microsoft.Extensions.Configuration (>= 10.0.2)
- Microsoft.Extensions.DependencyInjection (>= 10.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.