Pass a transaction (or any other object) to a property?
I have a property with a set and get method and it loads (in the get) and saves (in the set) data 开发者_如何学Goto/from ther DB. Now I want to have this in a transaction, which is a IDbTransaction in my case. The problem is, how could I give the property my transaction object? I already have the transaction in the code which uses the property...
Thanks :)
Have you tried System.Transactions.Transaction.Current
? It's a static property, documented here
You can wrap the call to your property with a TransactionScope
object. Any call within the using block will be part of the transaction.
using (TransactionScope scope = new TransactionScope())
{
// call properties and other code
scope.Complete(); // needed or transaction rolls back
}
精彩评论