Problem with TransactionScope

Description

When we use TransactionScope with NHibernate we have 2 problems:
1. Connection to db is not released between transactions (between unit tests).
2. QueryOver do not see changes made before invoking it.

Full description is in ReadMe file in attached project. In this attachment we provide unit tests to reproduce those problems.

Environment

Windows 7 .NET Framework 4.5 Visual Studio .NET 2012

Attachments

1

Activity

Show:

Frédéric Delaporte 
December 28, 2017 at 6:10 PM

Moved here.

Alex Zaytsev 
March 4, 2015 at 1:37 AM

Roman Podstawa 
November 18, 2013 at 8:44 AM

What I know is that in this scenario NH is not connected to the transaction from TransactionScope. And the workaround solves this problem. I don't know NH source code so I can't say where the problem is.

Maximilian Haru Raditya 
November 15, 2013 at 2:50 PM

So given your workaround, does it mean that in current NH code base such transaction enlistment isn't correctly done?

Roman Podstawa 
November 15, 2013 at 1:37 PM
(edited)

Here you have a workaround:

[Test] public void TransactionScopeProblem_Workaround() { using (TransactionScope tx = new TransactionScope()) { using (var session = _sessionFactory.OpenSession()) { if (System.Transactions.Transaction.Current != null) { ((DbConnection)session.Connection).EnlistTransaction(System.Transactions.Transaction.Current); } using (var t = session.BeginTransaction()) { Worker worker = new Worker(); session.Save(worker); t.Commit(); } } tx.Dispose(); } var workerCount = _sessionFactory.OpenSession().QueryOver<Worker>().RowCount(); Assert.AreEqual(0, workerCount); }

This test works good.

Obsolete

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created November 7, 2013 at 1:25 PM
Updated December 28, 2017 at 6:10 PM
Resolved December 28, 2017 at 6:10 PM
Who's Looking?