Make sure that your session is created AFTER the transactionscope.
I'm confused by your assertion. I have used NHibernate in production
applications using TransactionScope for transaction management.
NHibernate properly enlisted in the ambient transaction. There was no
need to call session.BeginTransaction()/tx.Commit() as well as new
TransactionScope()/scope.Complete(). Just the latter was sufficient
for proper transaction semantics. Are you using NHibernate 3.2? Can
you provide a test case demonstrating the issue that you're seeing?
James
The former would probably persist if you flushed the session. The problem is, there's absolutely nothing telling NH to save the changes to the DB.
Diego
Then, how would you handle this?var session = GetSession();var foo = session.Query<Foo>(...);using (var transactionScope = new TransactionScope())
{
foo.Bar = newValue;
transactionScope.Complete();
}
The update could never happen as there's no way for NH to catch the change.I't likely the same with other frameworks like EF; if you don't call SaveChanges (which is the method that creates the transaction, flushes and commits), completing the scope will do nothing.
Diego
Both of your examples are for inserts.In neither case the instantiation location is important (you can try)In neither case the object is a proxy, nor would it have to be even if it was already persistent.And in both cases, trying to update the object afterwards with just a TransactionScope would not work.Just accept that it's not technically feasible for NH (or any other framework) to do what you want, nor is it desirable for most people using it. Completing a scope and flushing a unit of work are different things.
Diego
Both of your examples are for inserts.In neither case the instantiation location is important (you can try)In neither case the object is a proxy, nor would it have to be even if it was already persistent.And in both cases, trying to update the object afterwards with just a TransactionScope would not work.Just accept that it's not technically feasible for NH (or any other framework) to do what you want, nor is it desirable for most people using it. Completing a scope and flushing a unit of work are different things.
Diego
There are a few problems:- What you posted is absolutely different from the NH-2107. There, the session is being opened inside the transactionscope, which is a point where an ambient transaction COULD be detected.
- I won't even try to compare this to the (discontinued) L2S, which doesn't use POCOs.- What is "the number of people asking for exactly the same thing"? There are thousands of projects using NH, none of which has problems with using NH transactions alone, or combined with TransactionScope. Five users, none of which seem to have looked at the implementation and implications of what they suggest, or provided a patch, are far from being a significative sample.
Diego
OK, is my last post on this thread. I won't waste more time, so feel free to continue your bashing.In Microsoft, all features start at minus 100 points, because they take effort to implement, document, and test for compatibility.So far, you have failed to prove that your feature goes beyond a minor convenience issue, and to resolve the potential inconsistencies, much less provide any actual pointers on how such a feature might be implemented.I don't know what you are "trying to start here", but I given examples and reasons why it would be hard (or impossible) to implement that in NH.Regarding the model: You can have N-transactions and transaction scopes per session; you just have to create the transactions inside the scopes (remember transactionscopes are primarily wrappers for distributed transactions). If your code uses different assumptions, that's fine, but don't blame NH for that.You are free to use any ORM you like (I do use EF in some projects, having choices is wonderful).
Diego
Perdón, debo haber estado hablando en español por error cuando expliqué que tu código no tenía nada que ver con el ticket que mencionaste.
Perdón, debo haber estado hablando en español por error cuando expliqué que tu código no tenía nada que ver con el ticket que mencionaste.
Diego
4. AFAIK You cannot use 2nd level cache when using distributed transactions.
4. AFAIK You cannot use 2nd level cache when using distributed transactions.Really? Is there some more information about this anywhere?