Vaccano
Vaccano

Reputation: 82527

Step out of a distributed transaction for one of my Entity Framework ObjectContexts

I am using NServiceBus with Distributed Transactions. Normally this works fantastic. Either my message succeeds or fails. All or nothing.

However, I am also trying to record diagnostic data to my database. This is done on a separate ObjectContext. For that, I would like it to save to the database regardless of the success or failure of the Distributed Transaction.

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

Upvotes: 3

Views: 588

Answers (3)

Adam Fyles
Adam Fyles

Reputation: 6050

NSB has a built in way to do auditing. I would recommend turning this on and dealing with the logging/audit trail in another endpoint.

Upvotes: 0

Andreas Öhlund
Andreas Öhlund

Reputation: 5273

One option (if using3.0) is to create a UoW:

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

And in there suppress the transaction and do the logging.

Upvotes: 1

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364409

Try this to suppress your ambient distributed transaction for auditing:

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

Upvotes: 5

Related Questions