Data Access
Excalibur provides data access abstractions that work alongside event sourcing and domain modeling. These patterns use Dapper for all SQL operations, avoiding Entity Framework to keep dependencies minimal and performance optimal.
Before You Start
- .NET 8.0+ (or .NET 9/10 for latest features)
- Install the required packages:
dotnet add package Excalibur.Data.Abstractions - Familiarity with dependency injection and domain modeling
In This Section
| Topic | Description |
|---|---|
| IDb Interface | Database connection abstraction with Dapper |
Key Abstractions
| Interface | Purpose |
|---|---|
IDb | Database connection abstraction |
IDataRequest | Query abstraction for data access |
IUnitOfWork | Transaction management |
Choosing Between Direct Dapper and IDataRequest
Excalibur supports two approaches for data access:
| Approach | Best For |
|---|---|
| Direct Dapper | Simple queries, quick ad-hoc access, projections |
| IDataRequest | Complex queries, testability, retry policies, correlation tracking |
// Direct Dapper: Simple and quick
var order = await _db.Connection.QuerySingleOrDefaultAsync<Order>(
"SELECT * FROM Orders WHERE Id = @Id", new { Id = orderId });
// IDataRequest: Encapsulated and testable
var request = new GetOrderByIdRequest(orderId);
var order = await request.ResolveAsync(_db.Connection);
See IDb Interface for detailed examples of both patterns.
Important Notes
- No Entity Framework: Excalibur uses Dapper for all SQL operations
- Data access is separate from event sourcing - use
IEventSourcedRepository<T>for event-sourced aggregates ResourceExceptionandConcurrencyExceptionare thrown for data access errors
Related Documentation
- Event Sourcing - Event-sourced aggregate persistence
- Domain Modeling - Aggregate design
See Also
- IDb Interface — Database connection abstraction with Dapper integration and IDataRequest pattern
- Data Providers Overview — Unified data access layer with pluggable providers for SQL, NoSQL, and cloud databases
- SQL Server Provider — Enterprise SQL Server data provider implementation