一个TransactionScope内DocumentDb写 [英] DocumentDb write within a transactionscope

查看:236
本文介绍了一个TransactionScope内DocumentDb写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个DocumentDb写像下面一个事务的一部分 -

I am trying to use a DocumentDb write as a part of a transaction like below -

using (var scope = new TransactionScope)
{
//first transaction

//write to document db

//third transaction
}

我认为,如果第三个交易失败,documentDb写入不会回退,我仍然看到集合中的文件。第一个事务(NEventStore在这种情况下)回滚完美。有谁知道,如果DocumentDb支持TrnasactionScope。如果我有一个嵌套的事务?

I observed that if the third transaction fails, documentDb write is not rolled back and I still see the document in the collection. The first transaction (NEventStore in this case) rolls back perfectly. Does anyone know if DocumentDb supports TrnasactionScope. What if I have a nested transaction?

谢谢!

编辑: 所以,看起来像的TransactionScope不支持DocumentDb,并因此它不知道他们。有没有办法从C#外部事务的DocumentDb交易的一部分?有没有人碰到这种情况下,使用前?

So looks like TransactionScope is not supported with DocumentDb and it knows nothing about them. Is there a way to make DocumentDb transactions part of an external transaction from C#? Has anyone come across this use case before?

编辑2:跟进问一答的<一个href="http://stackoverflow.com/questions/31826887/documentdb-transactions-as-a-part-of-an-external-transaction-scope">here作为建议

Edit 2: Follow-up question and answer here as suggested

推荐答案

DocumentDB操作是独立于的TransactionScope 。一旦操作的回报,它的完成。数据库服务并不知道的TransactionScope 任何事情,没有连接到它以任何方式。

DocumentDB operations are independent from TransactionScope. Once an operation returns, it's done. The database service doesn't know anything about TransactionScope and isn't connected to it in any way.

DocumentDB确实有它自己的事务范围,使用服务器端存储过程时。您可以在存储过程中的多个数据库调用,如果一切顺利,有在该存储过程退出隐式提交。如果出现错误,并抛出一个异常,一个隐含的回滚执行存储过程的范围内执行到数据库的所有操作。

DocumentDB does have a transaction scope of its own, when working with server-side stored procedures. You can have multiple database calls within the stored proc, and if everything is successful, there's an implicit commit upon the stored procedure exiting. If something goes wrong and an exception is thrown, an implicit rollback is executed for all operations performed to the database within the stored procedure's scope.

这篇关于一个TransactionScope内DocumentDb写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆