Reputation: 1978
I'm using a TransactionScope
in a model controller class that coordinates several lower level, data access classes. The data access classes each use their own LINQ DataContext
, and thanks to the magic of TransactionScope
, they all participate in the same transaction if one is present.
Under normal circumstances, this is perfect and everything works. However, I've added an activity logging class and one of the places it can write to is the database. Unfortunately, it automatically picks up on the TransactionScope
and if the transaction gets rolled back, so do all the log entries.
I've checked the Transaction
property of the DataContext
and it's null, as expected, so I'm not sure how to tell it to ignore the TransactionScope
.
Upvotes: 3
Views: 208
Reputation: 78210
In your logging class, wrap your using(new datacontext())
into:
using (var s = new TransactionScope(TransactionScopeOption.Suppress)) {
}
Upvotes: 3