Recently we have been introducing NHibernate and a domain layer to an older system that relies primarily on the Enterprise Library Data Access application block and stored procedures for database access.
This has mostly gone pretty smoothly, except in situations where we mix the two strategies inside a transaction. Enterprise Library and NHibernate both manage their own connections and if we try to wrap them both in a TransactionScope it gets promotes to a distributed transaction, causing all sorts of headaches. Wouldn't it be great if NHibernate and Enterprise Library could just share a single SqlConnection instead?
Luckily NHibernate makes this sort of thing really easy to achieve. All you need to do is write a custom IConnectionProvider that wraps Enterprise Library's Database.CreateConnection(). Then just drop into your hibernate.xml.cfg:
Note you don't need a connection.connection_string anymore because it retrieves it from the Enterprise Library's dataConfiguration section:
You can grab the code here: EntLibConnectionProvider.cs