DocumentDb交易的外部事务范围的一部分 [英] DocumentDb transactions as a part of an external transaction scope

查看:233
本文介绍了DocumentDb交易的外部事务范围的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从C#外部事务的DocumentDb交易的一部分?

这是从<一个后续问题href="http://stackoverflow.com/questions/31819243/documentdb-write-within-a-transactionscope">here而在交易3以下故障应回滚任何documentDb更新。

 使用(VAR范围=新的TransactionScope)
{
//第一笔交易

//写文件数据库

//第三个交易
}
 

解决方案

我通过实施<一个解决了这个href="https://msdn.microsoft.com/en-us/library/system.transactions.ienlistmentnotification(v=vs.110).aspx"相对=nofollow> IEnlistmentNotification 上DocumentDbRepository与DocumentDb n个以下方式进行交互 -

  1. 实现接口
  2. 请在构造函数中Transaction.Current的当前实例的一部分。 (或者,如果你正在使用依赖注入和对象是预先创建使用懒&LT之前的任何更新;>也可以在交易过程中考虑的构造函数调用
  3. 在创建/更新 - 保存旧的文件,或创建新的对象其实并保存selfLink
  4. 如果回滚被调用时,采取纠正措施与保存在上面的步骤所需的信息。

PS - 我可以分享伪code。如果有人有兴趣,请发表评论

Is there a way to make DocumentDb transactions part of an external transaction from C#?

This is a follow-up question from here and failure in transaction 3 below should rollback any documentDb updates.

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

//write to document db

//third transaction
}

解决方案

I solved this by implementing IEnlistmentNotification on DocumentDbRepository interacting with DocumentDb n the following way -

  1. Implement the interface
  2. Make the current instance part of the Transaction.Current in the constructor. (Or before any update if you are using dependency injection and object are created beforehand. Using Lazy<> can also be considered for constructor invocation during the transaction.
  3. During create/update - save the old document, or the fact that the new object was created and save the selfLink.
  4. If Rollback is called, take corrective action with the information saved in the step above.

PS - I can share the pseudo code if anyone is interested, please leave a comment.

这篇关于DocumentDb交易的外部事务范围的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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