在 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>();
}
(示例无耻地从这个相关问题中窃取)
在 NHibernate 源代码中,我可以看到它正在检查是否有正在进行的事务 (in SessionImpl.AutoFlushIfRequired
),但相关方法 ( SessionImpl.TransactionInProgress
) 不考虑环境事务 - 不像它的表亲ConnectionManager.IsInActiveTransaction
,它确实考虑环境事务。