DocumentDb transactions as a part of an external transaction scope

ぃ、小莉子 提交于 2019-12-24 02:56:13

问题


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
}

回答1:


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.



来源:https://stackoverflow.com/questions/31826887/documentdb-transactions-as-a-part-of-an-external-transaction-scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!