在 NHibernate 3.0 中,FlushMode.Auto
仅在环境事务下运行时不起作用(即,不启动 NHibernate 事务)。应该是?
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>();
}
(例如无耻地从 this related question 中窃取)
在 NHibernate 源代码中,我可以看到它正在检查是否有正在进行的事务(在
SessionImpl.AutoFlushIfRequired
中),但相关方法( SessionImpl.TransactionInProgress
)不考虑环境事务 - 与其表亲 ConnectionManager.IsInActiveTransaction
不同, 其中 考虑环境交易。
最佳答案
好消息。 感谢 Jeff Sternal(他很好地发现了问题)我更新了 https://nhibernate.jira.com/browse/NH-3583感谢 NH 的工作人员,已经有一个修复和拉取请求 所以在即将发布的 4.1.x.x 版本中,这个问题将得到修复。
关于NHibernate 3.0 : TransactionScope and Auto-Flushing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5187860/