Entity Framework - Generic Transaction Methods
We're currently using transactions with the Entity Framework, but might be switching to some other ORM in the future. What's the best way to implement the following...
BeginTransaction();
//Some update/insert/delete operations here
entity.Name = "Joe";
SaveChanges();
EndTransaction();
- We don't want to use the "using" statement
- We need it开发者_运维百科 to work with nested transactions
You can use TransactionScope ... and you can nest it in a try/catch/finally if you REALLY want to, though the "using" statement would be easier. Is there any specific reason you don't want to use "using"? I've used both together with quite some success, and it supports nested transactions.
- http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
- http://msdn.microsoft.com/en-us/library/bb738523.aspx
精彩评论