Flush separate Castle ActiveRecord Transaction, and refresh object in another Transaction

Posted by eanticev on Stack Overflow See other posts from Stack Overflow or by eanticev
Published on 2010-06-15T00:39:53Z Indexed on 2010/06/15 0:42 UTC
Read the original article Hit count: 432

I've got all of my ASP.NET requests wrapped in a Session and a Transaction that gets commited only at the very end of the request.

At some point during execution of the request, I would like to insert an object and make it visible to other potential threads - i.e. split the insertion into a new transaction, commit that transaction, and move on.

The reason is that the request in question hits an API that then chain hits another one of my pages (near-synchronously) to let me know that it processed, and thus double submits a transaction record, because the original request had not yet finished, and thus not committed the transaction record.

So I've tried wrapping the insertion code with a new SessionScope, TransactionScope(TransactionMode.New), combination of both, flushing everything manually, etc.

However, when I call Refresh on the object I'm still getting the old object state.

Here's some code sample for what I'm seeing:

            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

Any suggestions, ideas, and comments are appreciated!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about activerecord