RavenDB与Transaction Scope不能很好地协作

我有以下测试用例,我希望通过。 但它没有通过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().Customize(x => x.WaitForNonStaleResults()).ToList(); Assert.AreEqual(1, dogs.Count); scope.Complete(); } 

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

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

为了扩展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("dogs/1"); Assert.AreEqual(dog, dog2); scope.Complete(); } 

你甚至可以使用:

 Dog[] dogs = session.Advanced.LoadStartingWith("dogs"); 

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

在RavenDB中,在提交DTC事务之前,数据不会添加到任何索引中。