CoreEx.Database.SqlServer
4.0.0-preview-1
dotnet add package CoreEx.Database.SqlServer --version 4.0.0-preview-1
NuGet\Install-Package CoreEx.Database.SqlServer -Version 4.0.0-preview-1
<PackageReference Include="CoreEx.Database.SqlServer" Version="4.0.0-preview-1" />
<PackageVersion Include="CoreEx.Database.SqlServer" Version="4.0.0-preview-1" />
<PackageReference Include="CoreEx.Database.SqlServer" />
paket add CoreEx.Database.SqlServer --version 4.0.0-preview-1
#r "nuget: CoreEx.Database.SqlServer, 4.0.0-preview-1"
#:package CoreEx.Database.SqlServer@4.0.0-preview-1
#addin nuget:?package=CoreEx.Database.SqlServer&version=4.0.0-preview-1&prerelease
#tool nuget:?package=CoreEx.Database.SqlServer&version=4.0.0-preview-1&prerelease
CoreEx.Database.SqlServer
Provides the SQL Server (
Microsoft.Data.SqlClient) implementation ofIDatabase:SqlServerDatabase,SqlServerUnitOfWork, session-context stamping, outbox relay, SQL Server-specific parameter extensions, and OpenTelemetry metrics for outbox operations.
Overview
CoreEx.Database.SqlServer is the SQL Server provider package built on top of CoreEx.Database. It supplies concrete implementations of every abstract type in that package — SqlServerDatabase, SqlServerCommand, SqlServerDatabaseArgs, SqlServerDatabaseColumns — and adds SQL Server-specific capabilities: session context propagation via sp_set_session_context, structured error-code mapping from SQL Server error numbers to CoreEx semantic exceptions, and SqlServerUnitOfWork for transactional outbox support.
The error-code mapping convention means stored procedures can raise well-known user error numbers (56001–56010) to signal domain exceptions without any application-layer switch statements. Duplicate-constraint violations (error numbers 2601, 2627 by default) are automatically converted to DuplicateException.
The outbox sub-namespace provides ready-to-use SqlServerOutboxPublisher, SqlServerOutboxRelay, and SqlServerOutboxRelayHostedService with .NET Meter-backed counters and histograms for enqueue throughput and relay lag.
Key capabilities
- 🗃️ SqlServerDatabase: Concrete
IDatabaseforSqlConnection; maps SQL Server error numbers to CoreEx semantic exceptions; configurableDuplicateErrorNumbers;RowVersionencoded as Base64 string viaStringBase64Converter. - 🔢 Error-code convention: SQL user error numbers 56001–56007 and 56010 map to
ValidationException,BusinessException,AuthorizationException,ConcurrencyException,NotFoundException,ConflictException,DuplicateException, andDataConsistencyExceptionrespectively. - 👤 Session context:
SetSqlSessionContextAsync(ExecutionContext?)invokes[dbo].[spSetSessionContext](configurable) to stampUsername,Timestamp,TenantId, andUserIdinto the SQL Server session context for row-level security and audit triggers. - 🔁 SqlServerUnitOfWork:
IDatabaseUnitOfWorkimplementation wrappingTransactionAsyncwithSqlServerUnitOfWorkInvoker; optionally accepts anIEventPublisheroutbox for transactional event enqueuing. - 📤 Outbox relay:
SqlServerOutboxPublisher(writes to outbox table),SqlServerOutboxRelay(polls and publishes), andSqlServerOutboxRelayHostedService(timer-driven hosted service) — all SQL Server-specific subclasses of the baseCoreEx.Database.Outboxtypes. - 📊 Outbox metrics:
SqlServerMetricsexposes .NETMeterinstruments:sqlserver.outbox.enqueue(counter),sqlserver.outbox.relay.batch.size(counter),sqlserver.outbox.batch.oldest_lagandsqlserver.outbox.batch.newest_lag(histograms in ms). - 📡 OpenTelemetry:
CoreExSqlServerExtensions.AddCoreExSqlServerOpenTelemetrywiresSqlServerInvokeractivity sources and the outbox meter into the OTEL tracer and meter providers. - ⚙️ DI registration:
AddSqlServerDatabase<TDatabase>(services, configure?)registersSqlServerDatabaseas a scoped service;AddSqlServerUnitOfWork(services, configure?)registersSqlServerUnitOfWork.
Key types
| Type | Description |
|---|---|
SqlServerDatabase |
Concrete IDatabase for SqlConnection; error-number to exception mapping; RowVersion → StringBase64Converter; SetSqlSessionContextAsync. |
SqlServerUnitOfWork |
IDatabaseUnitOfWork implementation; wraps TransactionAsync with SqlServerUnitOfWorkInvoker; optional transactional outbox via IEventPublisher Outbox. |
SqlServerCommand |
DatabaseCommand subclass for SqlCommand; adds SQL Server-specific parameter handling and CommandTimeout support. |
SqlServerDatabaseArgs |
DatabaseArgs subclass with SQL Server-specific defaults (e.g. CommandTimeout). |
SqlServerDatabaseColumns |
DatabaseColumns subclass adding SessionContextUsernameName, SessionContextTimestampName, SessionContextTenantIdName, SessionContextUserIdName constants for session-context parameters. |
SqlServerMetrics |
Static .NET Meter with counters and histograms for outbox enqueue throughput and relay lag. |
SqlServerOutboxPublisher |
DatabaseOutboxPublisherBase for SQL Server; inserts event rows into the outbox table via a configurable stored procedure. |
SqlServerOutboxRelay |
DatabaseOutboxRelayBase<SqlServerDatabase, SqlServerOutboxRelay> with SQL Server-specific dequeue/complete SQL; records outbox metrics per batch. |
SqlServerOutboxRelayHostedService |
DatabaseOutboxRelayHostedServiceBase<SqlServerOutboxRelay> timer-driven hosted service for the SQL Server outbox relay. |
SqlServerExtensions |
IDatabase / DatabaseCommand extensions specific to SQL Server: Param helpers for SqlDbType-typed parameters and TVP (table-valued parameter) support. |
SqlServerInvoker |
DatabaseInvoker subclass for SQL Server; the Default singleton used by SqlServerDatabase. |
SqlServerUnitOfWorkInvoker |
InvokerBase<SqlServerUnitOfWork> wrapping TransactionAsync with OpenTelemetry spans and begin/commit/rollback log entries. |
Related Namespaces
CoreEx.Database- Abstract base types (Database<TConn>,DatabaseCommand,DatabaseRecord,DatabaseOutboxRelayBase,IDatabaseMapper) that all SQL Server types extend.CoreEx.Data-IUnitOfWorkandIDatabaseUnitOfWorkinterfaces implemented bySqlServerUnitOfWork.CoreEx.Events-IEventPublisheris the relay's publication target;SqlServerOutboxPublisherimplementsIEventPublisher.CoreEx.Invokers-SqlServerInvokerandSqlServerUnitOfWorkInvokerextendInvokerBasefor OpenTelemetry tracing.
Additional Resources
- Microsoft.Data.SqlClient - The ADO.NET driver this package uses.
- sp_set_session_context - SQL Server session-context stored procedure used by
SetSqlSessionContextAsync.
AI Usage Guide
An AGENTS.md file is included with this package. AI coding assistants (GitHub Copilot, Claude, Cursor, etc.) that support workspace-injected package documentation will automatically surface concise usage guidance, code examples, and Do Not rules for this package without requiring a local CoreEx checkout.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net9.0 is compatible. 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 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
- Aspire.Microsoft.Data.SqlClient (>= 13.1.1)
- CoreEx (>= 4.0.0-preview-1)
- CoreEx.Data (>= 4.0.0-preview-1)
- CoreEx.Database (>= 4.0.0-preview-1)
- Microsoft.Data.SqlClient (>= 6.1.3)
-
net8.0
- Aspire.Microsoft.Data.SqlClient (>= 13.1.1)
- CoreEx (>= 4.0.0-preview-1)
- CoreEx.Data (>= 4.0.0-preview-1)
- CoreEx.Database (>= 4.0.0-preview-1)
- Microsoft.Data.SqlClient (>= 6.1.3)
-
net9.0
- Aspire.Microsoft.Data.SqlClient (>= 13.1.1)
- CoreEx (>= 4.0.0-preview-1)
- CoreEx.Data (>= 4.0.0-preview-1)
- CoreEx.Database (>= 4.0.0-preview-1)
- Microsoft.Data.SqlClient (>= 6.1.3)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on CoreEx.Database.SqlServer:
| Package | Downloads |
|---|---|
|
CoreEx.UnitTesting
Core .NET extensions and abstractions for the testing of backend services. |
|
|
Beef.Database.SqlServer
Business Entity Execution Framework (Beef) SQL Server Database tool. |
|
|
NTangle
NTangle Change-Data-Capture framework/runtime. |
|
|
NTangle.CodeGen
NTangle Change-Data-Capture code-generation. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on CoreEx.Database.SqlServer:
| Repository | Stars |
|---|---|
|
Avanade/Beef
The Business Entity Execution Framework (Beef) framework, and the underlying code generation, has been primarily created to support the industrialization of API development.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0-preview-1 | 82 | 6/20/2026 |
| 3.31.0 | 4,181 | 2/1/2025 |
| 3.30.2 | 269 | 12/11/2024 |
| 3.30.1 | 270 | 12/9/2024 |
| 3.30.0 | 1,805 | 11/21/2024 |
| 3.29.0 | 641 | 11/19/2024 |
| 3.28.0 | 287 | 11/9/2024 |
| 3.27.3 | 630 | 10/23/2024 |
| 3.27.2 | 257 | 10/17/2024 |
| 3.27.1 | 351 | 10/15/2024 |
| 3.27.0 | 517 | 10/11/2024 |
| 3.26.0 | 270 | 10/3/2024 |
| 3.25.6 | 561 | 10/2/2024 |
| 3.25.5 | 292 | 9/25/2024 |
| 3.25.4 | 342 | 9/24/2024 |
| 3.25.3 | 305 | 9/18/2024 |
| 3.25.2 | 285 | 9/17/2024 |
| 3.25.1 | 333 | 9/16/2024 |
| 3.25.0 | 311 | 9/10/2024 |
| 3.24.1 | 363 | 8/7/2024 |