0

使用 NHibernate,在我的 NUnit 测试中,我可能会进行调用,例如session.Delete(_user)where _useris an persistent object。

我的问题似乎是,除非我在事务中包含此更新和任何其他更新,否则它永远不会成功。

所以,

CurrentSessionContext.Bind(GetHibernateSessionFactory().OpenSession());
ITransaction trans=session.BeginTransaction()
session.Delete(_user);
trans.Commit();
CurrentSessionContext.Unbind(GetHibernateSessionFactory())

作品。

但,

CurrentSessionContext.Bind(GetHibernateSessionFactory().OpenSession());
session.Delete(_user);
CurrentSessionContext.Unbind(GetHibernateSessionFactory())

没有,但没有报告异常或问题。

有任何想法吗?

4

1 回答 1

3

NHibernate 只会在刷新会话时向数据库发送更新/插入/删除。

您可以通过调用 Flush() 显式执行此操作,但您还应该查看配置:您也可以在那里指定默认的刷新行为。

有趣的阅​​读:

NHibernate ISession Flush:何时何地使用它,为什么? NHibernate Flush——它是如何工作的?

于 2013-01-10T12:53:28.300 回答