Skip to main content

Data Access

Excalibur provides data access abstractions that work alongside event sourcing and domain modeling. The SQL patterns use Dapper with explicit queries. This design does not establish a performance advantage over other data-access approaches; compare equivalent queries, materialization and transaction behavior on the chosen provider.

Before You Start​

In This Section​

TopicDescription
IDb InterfaceDatabase connection abstraction with Dapper
IDataRequestEncapsulated queries, DataRequest base class, and IDataRequestResolver

Key Abstractions​

InterfacePurpose
IDbDatabase connection abstraction
IDataRequestQuery abstraction for data access
IDataRequestResolverLightweight query executor with connection-per-call lifecycle
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 requirement: SQL requests support Dapper or explicit ADO execution
  • 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