DocumentDb交易的外部事务范围的一部分范围、事务、DocumentDb

由网友(余生是你)分享简介:有没有办法从C#外部事务的DocumentDb交易的一部分?这是从here而在交易3以下故障应回滚任何documentDb更新。 使用(VAR范围=新的TransactionScope){//第一笔交易//写文件数据库//第三个交易}解决方案 我通过实施 IEnlistmentNotification 上Docu...

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

这是从here而在交易3以下故障应回滚任何documentDb更新。

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

//写文件数据库

//第三个交易
}
 

解决方案

我通过实施 IEnlistmentNotification 上DocumentDbRepository与DocumentDb n个以下方式进行交互 -

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

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

基于电商交易流程,图解TCC事务分段提交

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.

阅读全文

相关推荐

最新文章