Exit a distributed transaction for one of my Entity Framework ObjectContexts

I am using NServiceBus with distributed transactions. This usually works fantastic. Either my post succeeds or fails. All or nothing.

However, I am also trying to write diagnostic data to my database. This is done for a separate ObjectContext. For this, I would like it to persist in the database regardless of the success or failure of the Distributed Transaction.

Is there a way to bind one (and only one) data context to a database outside of a distributed transaction? (And keep the rest in them?)

+3


source to share


3 answers


Try this to suppress your distributed transaction for auditing:



using (new TransactionScope(TransactionScopeOption.Suppress))
{
    // Create logging context and audit your data
}

      

+5


source


One option (if 3.0 is used) is to create UoW:

http://andreasohlund.net/2011/11/21/unit-of-work-in-nservicebus-3-0/



And there it suppresses the transaction and writes the log.

+1


source


NSB has a built in way of auditing . I would recommend enabling this and working with log / audit on a different endpoint.

0


source







All Articles