Dapper
Description
Dapper is the relational “micro-ORM” option in FlexBase: explicit SQL, minimal overhead, and high performance.
Flex wraps Dapper with Flex Dapper (a Dapper-first implementation of the Flex MicroORM abstraction). Your application code can stay provider-agnostic by using:
IFlexDapperRepositoryfor query/command helpersFlexDapperSql+ProviderSqlMapfor provider-specific SQL variantsBuilt-in soft-delete filtering (optional)
Paging helpers
Transaction helpers
If you prefer LINQ, change tracking, and migrations, see Entity Framework Core.
When to Use Dapper
High-performance reads (lists, dashboards, reporting)
✅ Use Dapper/Flex Dapper
Complex/hand-tuned SQL (CTEs, vendor features, query hints)
✅ Use Dapper/Flex Dapper
Bulk operations (insert/update many rows)
✅ Use Dapper/Flex Dapper
Simple table-centric CRUD on TFlex entities
✅ Use FlexDapperTableRepository<TEntity>
Rich domain graphs + change tracking + navigation properties
Prefer Entity Framework Core
Configuration in DI
appsettings.json
Where you store the connection string is app-specific, but most apps keep it under standard connection strings:
Sample usage (Queries / Handlers)
The typical pattern is: queries call QueryAsync/QuerySingleAsync, and handlers call ExecuteAsync/ExecuteScalarAsync, all through interfaces.
Query example (read model)
Handler example (command)
Common Patterns
Custom SQL (Provider-Agnostic)
Use ProviderSqlMap + FlexDapperSql.FromProviderMap(...) to keep provider differences in one place.
Paging
For custom queries, use QueryPageAsync with FlexDapperPagedQuery:
Transactions
Use WithTransactionAsync to ensure atomic multi-statement work.
Soft Delete Filter
Enable filtering with
FlexDapperRepositoryOptions.EnableSoftDeleteFilterand setSoftDeleteColumnName(commonlyIsDeleted).FlexDapperTableRepository<TEntity>automatically appends the soft-delete predicate when the filter is enabled.To temporarily include soft-deleted rows:
Testing
For unit tests, inject a fake
IFlexDapperConnectionFactoryand/or assert SQL text + parameters.For integration tests, use a real database (local/container) and reuse the same repository registrations.
See Also
Last updated