TransactionScope security check

I am working on an old project with almost nonexistent transactions, which leads to a lot of partial commits in case of error. SQL calls are a mix of raw ADO, Linq with Entities and EntityFramework, and I would like them to be executed in transactions.

To solve this problem, I look at the TransactionScope route. Can anyone tell me if it is possible to execute some kind of control check to determine in a method if it is triggered from a TransactionScope? Either use an attribute or some kind of validation on the TransactionScope itself. The ultimate goal is to throw some meaningful exception and keep track of areas that are missing transactions.

thank

+3


source to share


1 answer


If your code is running inside a TransactionScope block, then Transaction.Current != null

. You will need to add a usage for System.Transactions and a reference to System.Transactions.dll.



0


source







All Articles