我知道 NHibernate 支持环境事务,因为 NHibernate 会话在事务范围内参与环境事务。但是,有一些奇怪之处,请考虑以下测试:
[Test]
public void Transaction_RollsBackTransactionInsideOfAmbientTransaction_AmbientTransactionAborted()
{
// arrange
ISessionFactory sessionFactory = SessionFactoryOneTimeInitializer.GetTestSessionFactory();
ISession session = sessionFactory.OpenSession();
SessionFactoryOneTimeInitializer.CreateDataBaseSchemaIfRequiredByConfiguration(session);
using (new TransactionScope())
{
using (ITransaction transaction = session.BeginTransaction())
{
// act
transaction.Rollback();
}
// assert
Assert.AreEqual(TransactionStatus.Aborted, Transaction.Current.TransactionInformation.Status);
}
}
此测试失败。NHibernate 将如何确保环境事务不会持久化到数据库中?