DocumentDb交易的外部事务范围的一部分 [英] DocumentDb transactions as a part of an external transaction scope
问题描述
有没有办法从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个以下方式进行交互 -
- 实现接口
- 请在构造函数中Transaction.Current的当前实例的一部分。 (或者,如果你正在使用依赖注入和对象是预先创建使用懒&LT之前的任何更新;>也可以在交易过程中考虑的构造函数调用
- 在创建/更新 - 保存旧的文件,或创建新的对象其实并保存selfLink 。
- 如果回滚被调用时,采取纠正措施与保存在上面的步骤所需的信息。
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 -
- Implement the interface
- 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.
- During create/update - save the old document, or the fact that the new object was created and save the selfLink.
- 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屋!