RavenDB与Transaction Scope不能很好地协作

Qui*_*onn 2 c# transactionscope ravendb

我有以下测试用例,我希望通过.但它没有通过RavenDB.
如果我使用MsSql创建完全相同的测试,它确实通过.

        var connectionString = "Url=http://localhost:8080";
        var store = new DocumentStore();
        store.ParseConnectionString(connectionString);
        store.Initialize();
        using (var scope = new TransactionScope())
        using (var session = store.OpenSession())
        {
            session.Store(dog);
            session.SaveChanges();

            var dogs = session.Query<Dog>().Customize(x => x.WaitForNonStaleResults()).ToList();
            Assert.AreEqual(1, dogs.Count);
            scope.Complete();
        }
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写一些相同的代码,无论我选择什么数据库,这只是我试图通过的测试用例的一个例子.

我尝试过各种各样的东西,比如waitfornonstaleresults,以及allownonautheitative..something等等.

Dav*_*ike 6

为了扩展Ayende的答案,与MSSQL不同,文档存储(存储/加载操作)与索引存储是分开的,并且是唯一的ACID.索引存储不是事务性的,并且在完成对文档存储的更新后异步更新.在这种情况下,在事务提交后使用分布式(DTC)事务.这是设计的.

因此,虽然您的代码不能按预期工作,但这应该:

var connectionString = "Url=http://localhost:8080";
var store = new DocumentStore();
store.ParseConnectionString(connectionString);
store.Initialize();
using (var scope = new TransactionScope())
using (var session = store.OpenSession())
{
    Dog dog = new Dog { Id = "dogs/1" };
    session.Store(dog);
    session.SaveChanges();

    var dog2 = session.Load<Dog>("dogs/1");
    Assert.AreEqual(dog, dog2);
    scope.Complete();
}
Run Code Online (Sandbox Code Playgroud)

你甚至可以使用:

Dog[] dogs = session.Advanced.LoadStartingWith<Dog>("dogs");
Run Code Online (Sandbox Code Playgroud)

但是,任何要求索引存储数据(查询)的内容都不会返回,因为数据甚至还没有永久地添加到事务存储中,更不用说异步映射到索引存储中了.