【发布时间】:2011-08-06 09:34:29
【问题描述】:
我的 ISession 对象的 FlushMode 是 FlushMode.Commit。
我使用此处定义的工作单元和存储库模式: http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx
我记得看到一些例子,有些人在调用 Get() 后立即执行 Flush 或事务提交。我们是他们刚刚摆脱困境,还是有理由这样做?
根据我的测试:
[TestMethod]
public void TestMethod1()
{
Employee e;
IRepository<Employee> empRepo;
using(UnitOfWork.Start(Enums.Databases.MyDatabase))
{
empRepo = new Repository<Employee>();
e = empRepo.GetByID(21);
}
Debug.WriteLine(e.UserName);
}
我的 GetByID 存储库函数只调用 Session.Get(id) 并且我可以在输出窗口中查看用户名(在会话被终止之后)......那么在 Get 之后进行任何类型的刷新或事务提交有什么意义() ?如果那里有存档,我会理解的。
【问题讨论】:
标签: nhibernate transactions unit-of-work flush