This is a common question, but the explanations found so far and observed behaviour are some way apart.
We have want the following nHibernate strategy in our MVC website:
- A
SessionScopefor the request (to track changes) - An
ActiveRecord.TransactonScopeto wrap our inserts only (to enable rollback/commit of batch) - Selects to be outside a Transaction (to reduce extent of locks)
- Delayed Flush of inserts (so that our insert/updates occur as a UoW at end of session)
Now currently we:
- Don't get the implied transaction from the
SessionScope(with FlushAction Auto or Never) - If we use
ActiveRecord.TransactionScopethere is no delayed flush and any contained selects are also caught up in a long-running transaction.
I'm wondering if it's because we have an old version of nHibernate (it was from trunk very near 2.0).
We just can't get the expected nHibernate behaviour, and performance sucks (using NHProf and SqlProfiler to monitor db locks).