Cirreum.Persistence.SqlServer 1.0.9

dotnet add package Cirreum.Persistence.SqlServer --version 1.0.9
                    
NuGet\Install-Package Cirreum.Persistence.SqlServer -Version 1.0.9
                    
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="Cirreum.Persistence.SqlServer" Version="1.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cirreum.Persistence.SqlServer" Version="1.0.9" />
                    
Directory.Packages.props
<PackageReference Include="Cirreum.Persistence.SqlServer" />
                    
Project file
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 Cirreum.Persistence.SqlServer --version 1.0.9
                    
#r "nuget: Cirreum.Persistence.SqlServer, 1.0.9"
                    
#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 Cirreum.Persistence.SqlServer@1.0.9
                    
#: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=Cirreum.Persistence.SqlServer&version=1.0.9
                    
Install as a Cake Addin
#tool nuget:?package=Cirreum.Persistence.SqlServer&version=1.0.9
                    
Install as a Cake Tool

Cirreum.Persistence.SqlServer

NuGet Version NuGet Downloads GitHub Release License .NET

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
  • Azure Entra ID (Azure AD) authentication via DefaultAzureCredential
  • 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 Azure Entra ID authentication
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.

Azure Entra ID Authentication

When UseAzureAuthentication is enabled, the connection factory uses DefaultAzureCredential to acquire tokens for https://database.windows.net/.default. This supports:

  • Managed Identity (Azure VMs, App Service, AKS)
  • Azure CLI credentials (local development)
  • Visual Studio / VS Code credentials
  • Environment variables

Ensure your Azure SQL Database is configured for Azure AD authentication and the appropriate identity has been granted access.

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 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.

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.0.9 0 3/6/2026
1.0.8 124 2/5/2026
1.0.7 121 1/23/2026
1.0.6 101 1/22/2026
1.0.5 121 1/21/2026
1.0.4 120 1/12/2026
1.0.3 120 1/11/2026
1.0.2 115 1/6/2026
1.0.1 112 1/5/2026
1.0.0 111 1/5/2026