NHibernate 3.0:TransactionScope和自动刷新 [英] NHibernate 3.0: TransactionScope and Auto-Flushing

查看:132
本文介绍了NHibernate 3.0:TransactionScope和自动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在NHibernate 3.0中,仅在环境事务(即,不启动NHibernate事务)下运行时,FlushMode.Auto不起作用.应该吗?

using (TransactionScope scope = new TransactionScope()) 
{
    ISession session = sessionFactory.OpenSession();
    MappedEntity entity = new MappedEntity() { Name = "Entity", Value = 20 };
    session.Save(entity);

    entity.Value = 30;
    session.SaveOrUpdate(entity);

    // This returns one entity, when it should return none
    var list = session.
               CreateQuery("from MappedEntity where Value = 20").
               List<MappedEntity>();
}

(示例从此相关问题中被无耻地窃取了)

在NHibernate源代码中,我可以看到它正在检查是否正在进行事务(在SessionImpl.AutoFlushIfRequired中),但是相关方法(SessionImpl.TransactionInProgress)没有考虑环境事务-与表弟ConnectionManager.IsInActiveTransaction不同,该事务考虑.

解决方案

好消息.感谢Jeff Sternal(很好地确定了问题所在),我更新了

(Example shamelessly stolen from this related question)

In the NHibernate source I can see that's it's checking whether there's a transaction in progress (in SessionImpl.AutoFlushIfRequired), but the relevant method ( SessionImpl.TransactionInProgress) does not consider ambient transactions - unlike its cousin ConnectionManager.IsInActiveTransaction, which does consider ambient transactions.

解决方案

Good news. Thanks to Jeff Sternal (who nicely identified the problem) I updated https://nhibernate.jira.com/browse/NH-3583 and thanks to the NH staff, there's already a fix and a pull request so in the upcoming release 4.1.x.x this ISSUE will be fixed.

这篇关于NHibernate 3.0:TransactionScope和自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆