【问题标题】:Flush separate Castle ActiveRecord Transaction, and refresh object in another Transaction刷新单独的 Castle ActiveRecord Transaction,并在另一个 Transaction 中刷新对象
【发布时间】:2010-06-15 00:39:53
【问题描述】:

我的所有 ASP.NET 请求都包含在一个 Session 和一个仅在请求结束时提交的 Transaction 中。

在请求执行期间的某个时刻,我想插入一个对象并使其对其他潜在线程可见 - 即将插入拆分为一个新事务,提交该事务,然后继续。

原因是有问题的请求访问了一个 API,然后该 API 链接访问了我的另一个页面(接近同步),让我知道它已处理,因此重复提交了交易记录,因为原始请求没有尚未完成,因此未提交交易记录。

所以我尝试使用新的 SessionScope、TransactionScope(TransactionMode.New)、两者的组合、手动刷新所有内容等来包装插入代码。

但是,当我在对象上调用 Refresh 时,我仍然得到旧的对象状态。

这是我所看到的一些代码示例:

Post outsidePost = Post.Find(id); // status of this post is Status.Old
using (TransactionScope transaction = new TransactionScope(TransactionMode.New))
{
    Post p = Post.Find(id);
    p.Status = Status.New; // new status set here
    p.Update();

    SessionScope.Current.Flush();
    transaction.Flush();
    transaction.VoteCommit();
}
outsidePost.Refresh();
// refresh doesn't get the new status, status is still Status.Old

感谢任何建议、想法和 cmets!

【问题讨论】:

    标签: asp.net nhibernate castle-activerecord transactions


    【解决方案1】:

    我以前遇到过类似的问题,与隔离级别有关。默认隔离级别设置为“快照”,在 SQL Server 上运行时,这意味着第一个事务自启动以来不会看到任何更改。也许这是您的隔离级别?

    如果没有,请尝试在处理完上面的 TransactionScope 后直接创建一个全新的 TransactionScope,看看是否可以将其读回为 New。如果不能,可能与外部交易无关。

    希望对您有所帮助。

    马库斯

    【讨论】:

    • 谢谢马库斯,已经尝试过了,但不幸的是它没有成功。我刚刚结束了在 ActiveRecord 之外的整个事情。
    猜你喜欢
    • 1970-01-01
    • 2012-09-19
    • 2017-06-03
    • 2012-05-25
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    • 2011-06-16
    相关资源
    最近更新 更多