How do I do nested transactions in NHibernate?

前端 未结 4 1138
一生所求
一生所求 2020-12-05 14:39

Can I do nested transactions in NHibernate, and how do I implement them? I\'m using SQL Server 2008, so support is definitely in the DBMS.

I find that if I try somet

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 15:07

    NHibernate sessions don't support nested transactions.

    The following test is always true in version 2.1.2:

    var session = sessionFactory.Open();
    var tx1 = session.BeginTransaction();
    var tx2  = session.BeginTransaction();
    Assert.AreEqual(tx1, tx2);
    

    You need to wrap it in a TransactionScope to support nested transactions.

    MSDTC must be enabled or you will get error:

    {"Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool."}

提交回复
热议问题