Xpandables.Data
10.0.1
See the version list below for details.
dotnet add package Xpandables.Data --version 10.0.1
NuGet\Install-Package Xpandables.Data -Version 10.0.1
<PackageReference Include="Xpandables.Data" Version="10.0.1" />
<PackageVersion Include="Xpandables.Data" Version="10.0.1" />
<PackageReference Include="Xpandables.Data" />
paket add Xpandables.Data --version 10.0.1
#r "nuget: Xpandables.Data, 10.0.1"
#:package Xpandables.Data@10.0.1
#addin nuget:?package=Xpandables.Data&version=10.0.1
#tool nuget:?package=Xpandables.Data&version=10.0.1
System.Data
ADO.NET repository, unit of work, and SQL builder infrastructure for .NET.
Overview
System.Data provides a lightweight ADO.NET data access layer with Repository and Unit of Work patterns, type-safe query specifications, SQL builders for multiple dialects, and connection management. All operations execute immediately against the database (no change tracking).
Built for .NET 10 with full async support.
Features
Repository Pattern
IDataRepository— Base repository marker (implementsIDisposable,IAsyncDisposable)IDataRepository<TData>— Generic repository withQueryAsync,InsertAsync,UpdateAsync,DeleteAsyncDataRepository<TData>— Default ADO.NET repository implementationIDataRequiresUnitOfWork— Marker for pipeline UoW integration
Query Specifications
DataSpecification— Static factory withFor<TData>()methodIDataSpecification<TData, TResult>— Type-safe query specification
Unit of Work
IDataUnitOfWork— Transaction management withGetRepository<T>(),BeginTransactionAsync()DataUnitOfWork— Default ADO.NET unit of work implementationIDataTransaction— Transaction abstraction withCommitAsync(),RollbackAsync()DataTransaction— Default transaction implementation
SQL Builders
IDataSqlBuilder— SQL builder interfaceMsDataSqlBuilder— SQL Server SQL builderPostgreDataSqlBuilder— PostgreSQL SQL builderMyDataSqlBuilder— MySQL SQL builderDataSqlBuilderFactory— Factory for SQL buildersDataSqlBuilderBase— Base class for custom builders
Connection Management
IDataDbConnectionFactory— Database connection factoryDataDbConnectionFactory— Default connection factoryIDataDbConnectionScope— Scoped connection wrapperDataDbConnectionScope— Default scoped connectionIDataDbConnectionFactoryProvider— Provider for connection factoriesDataDbConnectionFactoryProvider— Default providerDbProviders— Provider constants (MsSqlServer,PostgreSql,MySql)
SQL Mapping
IDataSqlMapper— Maps specifications to SQLDataSqlMapper— Default SQL mapper implementation
Entity Updates
DataUpdater— Fluent API for building ADO.NET update operationsIDataPropertyUpdate— Property update abstraction
Command Interceptor
IDataCommandInterceptor— Intercept command execution for logging, telemetry, and diagnosticsDataCommandInterceptor— Base no-op implementation with virtual methods for selective overrideDataLoggingCommandInterceptor— Default structured logging implementation using[LoggerMessage]source generationDataCommandInterceptorOptions— Options for sensitive data logging, custom category, and slow command thresholdDataCommandContext— Context record with SQL text, parameters, operation type, and entity nameDataCommandOperationType— Enum:Reader,Scalar,NonQuery
Installation
dotnet add package Xpandables.Data
Quick Start
Register Services
using Microsoft.Extensions.DependencyInjection;
// Register SQL Server connection
services.AddXDataDbConnectionMsSqlServer(connectionString);
// Or PostgreSQL
services.AddXDataDbConnectionPostgreSql(connectionString);
// Or MySQL
services.AddXDataDbConnectionMySql(connectionString);
// Register SQL builder
services.AddXDataMsSqlBuilder(); // SQL Server
services.AddXDataPostgreSqlBuilder(); // PostgreSQL
services.AddXDataMySqlBuilder(); // MySQL
// Register SQL mapper
services.AddXDataSqlMapper();
// Register connection scope
services.AddXDataDbConnectionScope();
// Register unit of work and repositories
services.AddXDataUnitOfWork();
services.AddXDataRepositories(typeof(Program).Assembly);
Use the Repository
using System.Data;
public class OrderService(IDataUnitOfWork unitOfWork)
{
public async Task CreateOrderAsync(
Order order, CancellationToken ct)
{
await using var transaction = await unitOfWork
.BeginTransactionAsync(ct);
try
{
var repo = unitOfWork
.GetRepository<Order>();
await repo.InsertAsync([order], ct);
await transaction.CommitAsync(ct);
}
catch
{
await transaction.RollbackAsync(ct);
throw;
}
}
}
Query with Specifications
using System.Data;
var spec = DataSpecification
.For<Product>()
.Where(p => p.IsActive)
.OrderBy(p => p.Name)
.Skip(0)
.Take(20)
.Select(p => new ProductDto(p.Id, p.Name, p.Price));
await foreach (var product in repository.QueryAsync(spec, ct))
{
Console.WriteLine(product.Name);
}
Command Interceptor
A DataLoggingCommandInterceptor is registered automatically when you call AddXDataUnitOfWork(). It logs all command execution using structured ILogger output with [LoggerMessage] source generation:
| Event | Log Level | Content |
|---|---|---|
| Before execution | Debug |
SQL text, parameter names (or values if enabled) |
| After execution | Information |
Duration, rows affected, SQL text |
| Slow command | Warning |
Duration exceeding threshold |
| Failed execution | Error |
Duration, SQL text, exception |
Configure Options
services.AddXDataCommandInterceptor(options =>
{
// Log parameter values (default: false — only names are logged)
options.EnableSensitiveDataLogging = true;
// Custom log category (default: null — uses DataLoggingCommandInterceptor type name)
options.CategoryName = "MyApp.Database";
// Commands exceeding this threshold log at Warning (default: null — disabled)
options.SlowCommandThreshold = TimeSpan.FromSeconds(2);
});
services.AddXDataUnitOfWork(); // safe — TryAdd won't overwrite
Custom Interceptor
To fully replace the logging interceptor with your own implementation:
public sealed class MetricsCommandInterceptor : DataCommandInterceptor
{
public override ValueTask CommandExecutedAsync(
DataCommandContext context, TimeSpan duration, int? rowsAffected,
CancellationToken cancellationToken = default)
{
// Push metrics to your observability system
return ValueTask.CompletedTask;
}
}
services.AddXDataCommandInterceptor<MetricsCommandInterceptor>();
services.AddXDataUnitOfWork();
Registration behavior:
AddXDataUnitOfWork()auto-registers theDataLoggingCommandInterceptorviaTryAdd(won't overwrite a previously registered custom interceptor).AddXDataCommandInterceptor(Action?)configures options via theIOptions<T>pipeline and registers the logging interceptor.AddXDataCommandInterceptor<T>()usesReplaceto swap the current registration.- If you register your custom interceptor before
AddXDataUnitOfWork(), it is preserved.
---
## Core Types
| Type | Description |
|------|-------------|
| `IDataRepository<TData>` | Generic ADO.NET repository |
| `IDataUnitOfWork` | ADO.NET transaction coordinator |
| `IDataTransaction` | Transaction with commit/rollback |
| `DataSpecification` | Query specification factory |
| `IDataSqlBuilder` | SQL builder interface |
| `IDataDbConnectionFactory` | Connection factory |
| `DataUpdater` | Fluent update builder |
| `IDataRequiresUnitOfWork` | Pipeline UoW marker |
| `IDataCommandInterceptor` | Command execution interceptor |
| `DataLoggingCommandInterceptor` | Default structured logging interceptor |
| `DataCommandInterceptorOptions` | Interceptor configuration options |
## DI Extension Methods
| Method | Description |
|--------|-------------|
| `AddXDataDbConnectionMsSqlServer(cs)` | Register SQL Server connection |
| `AddXDataDbConnectionPostgreSql(cs)` | Register PostgreSQL connection |
| `AddXDataDbConnectionMySql(cs)` | Register MySQL connection |
| `AddXDataMsSqlBuilder()` | Register SQL Server SQL builder |
| `AddXDataPostgreSqlBuilder()` | Register PostgreSQL SQL builder |
| `AddXDataMySqlBuilder()` | Register MySQL SQL builder |
| `AddXDataSqlMapper()` | Register SQL mapper |
| `AddXDataUnitOfWork()` | Register unit of work (auto-registers logging interceptor) |
| `AddXDataCommandInterceptor()` | Register logging interceptor with default options |
| `AddXDataCommandInterceptor(Action)` | Register logging interceptor with custom options |
| `AddXDataCommandInterceptor<T>()` | Replace interceptor with custom implementation |
| `AddXDataRepositories(assemblies)` | Register repositories from assemblies |
| `AddXDataDbConnectionScope()` | Register scoped connection |
---
## 📚 Related Packages
| Package | Description |
|---------|-------------|
| **Xpandables.Entities** | Entity abstractions with lifecycle tracking |
| **Xpandables.Events.Data** | Event store built on System.Data |
---
## 📄 License
Apache License 2.0 — Copyright © Kamersoft 2025
| 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
- Microsoft.Extensions.Configuration (>= 10.0.3)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.3)
- Microsoft.Extensions.Configuration.Json (>= 10.0.3)
- Microsoft.Extensions.DependencyInjection (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- Microsoft.Extensions.Primitives (>= 10.0.3)
- Xpandables.AsyncPaged (>= 10.0.1)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Xpandables.Data:
| Package | Downloads |
|---|---|
|
Xpandables.Events
Event-driven architecture: in-process publish/subscribe, event-sourced aggregates and an event store, outbox and inbox with a hosted scheduler, over Xpandables.Data; Native AOT compatible. |
|
|
Xpandables.Events.Data
Events ADO.NET implementation. |
|
|
Xpandables.Results.Pipelines
Pipeline pattern implementation. |
|
|
Xpandables.AspNetCore.Net
ASP.NET Core minimal API integration of the Xpandables libraries: Result to HTTP responses and problem details, endpoint filters, routes, request context, pipeline behaviors and DI extensions; Native AOT compatible. |
GitHub repositories
This package is not used by any popular GitHub repositories.