1

在单个事务范围内,我试图将数据保存到两个单独的 Raven 数据库(在同一个 Raven 服务器上)。

但是,第二个会话中的更改不会保存到服务器。

这是我正在使用的代码:

var documentStore = new DocumentStore { Url = "http://localhost:8081/" };

documentStore.Initialize();

documentStore.DatabaseCommands.EnsureDatabaseExists("database1");
documentStore.DatabaseCommands.EnsureDatabaseExists("database2");

using (var ts = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    using (var session1 = documentStore.OpenSession("database1"))
    {
        session1.Store(new Entity {Id = "1"});
        session1.SaveChanges();
    }

    using (var session2 = documentStore.OpenSession("database2"))
    {
        session2.Store(new Entity {Id = "2"});
        session2.SaveChanges();
    }

    ts.Complete();
}

我可以看到session1保存到的database1更改,session2但未保存到的更改database2。我尝试过使用 RavenDb build 992 和 build 2360

根据 Raven 文档,支持跨数据库的事务。

我怎样才能得到session2要提交的更改?

4

1 回答 1

2

分布式事务需要时间来提交。您可以Thread.Sleep在检查结果之前稍等片刻,也可以在检查结果的会话中设置一个特殊属性:

session.Advanced.AllowNonAuthoritativeInformation = false;

这似乎是一个错误,但实际上是设计使然。阅读RavenDB 文档中的使用 System.Transactions

(仅供参考 - 在我检查之前我也不知道这一点。)

于 2013-05-15T16:12:55.753 回答