Cirreum.Persistence.SqlServer
1.1.4
dotnet add package Cirreum.Persistence.SqlServer --version 1.1.4
NuGet\Install-Package Cirreum.Persistence.SqlServer -Version 1.1.4
<PackageReference Include="Cirreum.Persistence.SqlServer" Version="1.1.4" />
<PackageVersion Include="Cirreum.Persistence.SqlServer" Version="1.1.4" />
<PackageReference Include="Cirreum.Persistence.SqlServer" />
paket add Cirreum.Persistence.SqlServer --version 1.1.4
#r "nuget: Cirreum.Persistence.SqlServer, 1.1.4"
#:package Cirreum.Persistence.SqlServer@1.1.4
#addin nuget:?package=Cirreum.Persistence.SqlServer&version=1.1.4
#tool nuget:?package=Cirreum.Persistence.SqlServer&version=1.1.4
Cirreum.Persistence.SqlServer
SQL Server provider for Cirreum.Persistence.Sql with Azure Entra ID authentication support
Overview
Cirreum.Persistence.SqlServer is a SQL Server-specific implementation of the ISqlConnectionFactory interface from the Cirreum.Persistence.Sql abstraction layer. It provides:
- SQL Server connection factory with Dapper integration
- Entra (Azure AD) token authentication, with credential selection via the instance's
Credentialblock and tenant pinning via itsIdentifier - Health check support for service monitoring
- Integration with the Cirreum Service Provider framework
For query extensions, pagination, transaction chaining, and constraint handling, see the Cirreum.Persistence.Sql documentation.
Installation
dotnet add package Cirreum.Persistence.SqlServer
Quick Start
Basic Registration
builder.AddSqlServer("default", "Server=localhost;Database=MyDb;Trusted_Connection=True;");
With Azure Entra ID Authentication
builder.AddSqlServer("default", settings =>
{
settings.ConnectionString = "Server=myserver.database.windows.net;Database=MyDb;";
settings.UseAzureAuthentication = true;
});
With Full Configuration
builder.AddSqlServer("default", settings =>
{
settings.ConnectionString = configuration.GetConnectionString("SqlServer")!;
settings.UseAzureAuthentication = true;
settings.CommandTimeoutSeconds = 60;
}, healthOptions =>
{
healthOptions.Query = "SELECT 1";
healthOptions.Timeout = TimeSpan.FromSeconds(5);
});
Configuration Options
SqlServerInstanceSettings
| Property | Type | Default | Description |
|---|---|---|---|
ConnectionString |
string |
- | SQL Server connection string |
UseAzureAuthentication |
bool |
false |
Enable Entra (Azure AD) token authentication |
Credential |
CredentialSettings? |
null |
Inherited. Selects whose identity acquires tokens (Default / ManagedIdentity / Developer, with optional IdentityId). Only valid with UseAzureAuthentication = true |
Identifier |
string? |
null |
Inherited. The Entra tenant to authenticate against |
CommandTimeoutSeconds |
int |
30 |
Default command timeout in seconds |
SqlServerHealthCheckOptions
| Property | Type | Default | Description |
|---|---|---|---|
Query |
string |
"SELECT 1" |
SQL query to execute for health checks |
Timeout |
TimeSpan |
5s |
Health check timeout |
Usage
Inject ISqlConnectionFactory and use the query/command extensions from Cirreum.Persistence.Sql:
public class OrderRepository(ISqlConnectionFactory db)
{
public async Task<Result<OrderDto>> GetOrderAsync(Guid orderId, CancellationToken ct)
{
await using var conn = await db.CreateConnectionAsync(ct);
return await conn.GetAsync<OrderDto>(
"SELECT * FROM Orders WHERE OrderId = @Id",
new { Id = orderId },
key: orderId,
ct);
}
public async Task<Result<Guid>> CreateOrderAsync(CreateOrder cmd, CancellationToken ct)
{
await using var conn = await db.CreateConnectionAsync(ct);
var orderId = Guid.CreateVersion7();
return await conn.InsertAndReturnAsync(
"""
INSERT INTO Orders (OrderId, CustomerId, Amount, CreatedAt)
VALUES (@OrderId, @CustomerId, @Amount, @CreatedAt)
""",
new { OrderId = orderId, cmd.CustomerId, cmd.Amount, CreatedAt = DateTime.UtcNow },
() => orderId,
uniqueConstraintMessage: "Order already exists",
ct: ct);
}
}
Multiple Instances
Register multiple SQL Server instances with different keys:
builder.AddSqlServer("primary", primaryConnectionString);
builder.AddSqlServer("reporting", reportingConnectionString);
// Inject with [FromKeyedServices]
public class ReportService([FromKeyedServices("reporting")] ISqlConnectionFactory db)
{
// ...
}
DateOnly and TimeOnly Support
This package includes built-in Dapper type handlers for DateOnly and TimeOnly, allowing you to use these types directly in your models and queries:
public record Appointment(int Id, DateOnly Date, TimeOnly StartTime, TimeOnly EndTime);
// Query with DateOnly/TimeOnly parameters
var appointments = await conn.QueryAsync<Appointment>(
"SELECT * FROM Appointments WHERE Date = @Date AND StartTime > @MinTime",
new { Date = new DateOnly(2026, 1, 15), MinTime = new TimeOnly(9, 0) });
// Insert with DateOnly/TimeOnly values
await conn.ExecuteAsync(
"INSERT INTO Appointments (Date, StartTime, EndTime) VALUES (@Date, @StartTime, @EndTime)",
new { Date = DateOnly.FromDateTime(DateTime.Today), StartTime = new TimeOnly(9, 30), EndTime = new TimeOnly(10, 0) });
The type handlers are registered automatically when the package is loaded.
Entra (Azure AD) Authentication
When UseAzureAuthentication is enabled, the connection factory acquires tokens for
https://database.windows.net/.default using the identity selected by the instance's
Credential block:
| Mode | Identity used |
|---|---|
Default (or no block) |
The default credential chain — environment, managed identity, developer tooling. IdentityId pins the chain's managed-identity leg to a specific user-assigned identity |
ManagedIdentity |
Managed identity only — system-assigned, or the user-assigned identity named by IdentityId |
Developer |
Developer tooling only — Visual Studio, Azure CLI, Azure PowerShell |
The instance's Identifier names the Entra tenant to authenticate against; leave it unset to
use the credential's default tenant.
{
"ConnectionString": "Server=myserver.database.windows.net;Database=MyDb;",
"UseAzureAuthentication": true,
"Identifier": "00000000-0000-0000-0000-000000000000", // Entra tenant
"Credential": {
"Mode": "ManagedIdentity",
"IdentityId": "11111111-1111-1111-1111-111111111111" // user-assigned MI client id
}
}
A Credential block on an instance with UseAzureAuthentication = false is rejected at
registration — the block selects a token identity, so on a connection-string-authenticated
instance it could only ever bind and silently do nothing.
Ensure your Azure SQL Database is configured for Entra authentication and the selected identity has been granted access.
Related Packages
| Package | Description |
|---|---|
| Cirreum.Persistence.Sql | Database-agnostic SQL abstraction layer |
| Cirreum.Persistence.Sqlite | SQLite provider |
| Cirreum.Persistence.MySql | MySQL provider (coming soon) |
| Cirreum.Persistence.PostgreSql | PostgreSQL provider (coming soon) |
License
This project is licensed under the MIT License - see the LICENSE file for details.
Cirreum Foundation Framework Layered simplicity for modern .NET
| 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. |
-
net10.0
- Azure.Identity (>= 1.21.0)
- Cirreum.Domain (>= 4.3.1)
- Cirreum.Persistence.Sql (>= 1.0.12)
- Cirreum.ServiceProvider (>= 1.1.3)
- Dapper (>= 2.1.79)
- Microsoft.Data.SqlClient (>= 7.0.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Cirreum.Persistence.SqlServer:
| Package | Downloads |
|---|---|
|
Cirreum.Runtime.Persistence
The Runtime Persistence service configuration. |
|
|
Cirreum.Runtime.Persistence.SqlServer
The Runtime Persistence service configuration for SqlServer. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.4 | 0 | 8/24/2026 |
| 1.1.3 | 60 | 8/20/2026 |
| 1.1.2 | 45 | 8/19/2026 |
| 1.1.1 | 82 | 8/17/2026 |
| 1.1.0 | 123 | 8/4/2026 |
| 1.0.44 | 127 | 7/31/2026 |
| 1.0.43 | 131 | 7/31/2026 |
| 1.0.42 | 127 | 7/30/2026 |
| 1.0.41 | 126 | 7/27/2026 |
| 1.0.40 | 127 | 7/25/2026 |
| 1.0.39 | 104 | 7/24/2026 |
| 1.0.38 | 123 | 7/20/2026 |
| 1.0.37 | 120 | 7/19/2026 |
| 1.0.36 | 149 | 7/7/2026 |
| 1.0.35 | 112 | 7/5/2026 |
| 1.0.34 | 139 | 7/4/2026 |
| 1.0.33 | 120 | 7/4/2026 |
| 1.0.32 | 110 | 7/4/2026 |
| 1.0.31 | 144 | 5/11/2026 |
| 1.0.30 | 135 | 5/7/2026 |