Skip to main content

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

TopicDescription
IDb InterfaceDatabase connection abstraction with Dapper

Key Abstractions

InterfacePurpose
IDbDatabase connection abstraction
IDataRequestQuery abstraction for data access
IUnitOfWorkTransaction management

Choosing Between Direct Dapper and IDataRequest

Excalibur supports two approaches for data access:

ApproachBest For
Direct DapperSimple queries, quick ad-hoc access, projections
IDataRequestComplex 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
  • ResourceException and ConcurrencyException are thrown for data access errors

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