是否有必要在事务中包装 nHibernate future ?
如:
using (var s = sf.OpenSession())
using (var tx = s.BeginTransaction())
{
var blogs = s.CreateCriteria<Blog>()
.SetMaxResults(30)
.List<Blog>();
var countOfBlogs = s.CreateCriteria<Blog>()
.SetProjection(Projections.Count(Projections.Id()))
.UniqueResult<int>();
Console.WriteLine("Number of blogs: {0}", countOfBlogs);
foreach (var blog in blogs)
{
Console.WriteLine(blog.Title);
}
tx.Commit();
}
从这里开始:
https://ayende.com/blog/3979/nhibernate-futures
我看不出这样做的理由。它是选择而不是插入或更新等。
最佳答案
当 NHibernate 查询未显式包装在事务中时,它被称为“隐式事务”,这是不鼓励的,并且具有各种含义,包括使二级缓存无效。这一切都在这里解释:
https://hibernatingrhinos.com/Products/nhprof/learn#DoNotUseImplicitTransactions
节选:
Even if we are only reading data, we should use a transaction, because using transactions ensures that we get consistent results from the database. NHibernate assumes that all access to the database is done under a transaction, and strongly discourages any use of the session without a transaction.
关于c# - 是否有必要在交易中包装 nHibernate future ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43097763/