This is a common question, but the explanations found so far and observed behaviour are some way apart.
We have want the following nHbernate strategy in our MVC website:
- A
SessionScope
for the request (to track changes) - A
ActiveRecord.TransacitonScope
to 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 the
ActiveRecord.TransacationScope
there is no delayed flush & any contained selects are also caught up in a long-running transaction.
I'm wondering if we've an old version of nHibernate (it was from trunk very near to 2.0).
We just can't get the expected nHibernate behaviour, and performance sucks (using NHProf and SqlProfiler to monitor db locks).