Refactoring ADO.NET - SqlTransaction vs. TransactionScope

前端 未结 6 659
悲哀的现实
悲哀的现实 2020-12-04 23:58

I have \"inherited\" a little C# method that creates an ADO.NET SqlCommand object and loops over a list of items to be saved to the database (SQL Server 2005).

Right

6条回答
  •  甜味超标
    2020-12-05 00:38

    Also late... You can easily have "nested" transactions in the business layer even if the database doesn't support nested transactions. .NET controls the nesting and ends up using one database transaction (at least in the case of SQL Server 2008+). This makes it much easier to reuse data access code outside of its original intent, as part of a larger transaction.

提交回复
热议问题