NHibernate 3.0:TransactionScope和自动刷新 [英] NHibernate 3.0: TransactionScope and Auto-Flushing
问题描述
在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 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屋!SessionImpl.AutoFlushIfRequired
), but the relevant method ( SessionImpl.TransactionInProgress
) does not consider ambient transactions - unlike its cousin ConnectionManager.IsInActiveTransaction
, which does consider ambient transactions.