DocumentDb Operations as Part of an External Transaction

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

This is the next question from here , and a failure in transaction 3 below should rollback any updates to documentDb.

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

//write to document db

//third transaction
}

      

+2


source to share


1 answer


I solved it by implementing IEnlistmentNotification in DocumentDbRepository interacting with DocumentDb n as follows -

  • Implement interface
  • Make the current part of the Transaction.Current instance in the constructor. (Or before any update, if you are using dependency injection and the object is created in advance. Using Lazy <> could also be considered for calling the constructor during a transaction.
  • During creation / update - save the old document or the fact of creating a new object and save selfLink.
  • If Rollback is called, take corrective action on the information saved in the previous step.


PS - I can share pseudocode, if anyone is interested please leave a comment.

+2


source







All Articles