We are using the Enterprise Library as a standard DAL. Now, I would like to enjoy the benefits of Dapper. Looking at the implementation it is just extending the connection class.
Is it conceivable to set Dapper to extend Enterprise Library so we can enjoy both worlds?
Or maybe someone already created this?
Yes, it is conceivable, and it works pretty well. We’re using Dapper to supplement some older EntLib code, and simple queries are quick and painless. The biggest challenge was getting Transactions to work properly. You don’t mention which version of EntLib you are using, but 4.0 and newer manage connections inside of TransactionScopes, so if you try to open another connection for Dapper inside of a scope with EntLib it will automatically escalate from a lightweight local transaction to DTC (Distributed Transaction Coordinator). EntLib doesn’t really provide a way to grab the current open connection, so you have to derive from the Database class and expose the GetOpenConnection method.
Then use it something like this:
If you have larger transaction scopes then you have to check to see if you are in an active transaction before you close each connection.