C# System.Transactions Vs TransactionScope

后端 未结 1 1448
执笔经年
执笔经年 2021-01-28 22:04

Based on this article here as well as the question: Difference Between Transaction and TransactionScope we know that TransactionScope

The Tr

1条回答
  •  执笔经年
    2021-01-28 22:19

    Looking around various resources, I stumbled to the following which partially answers my question: Working with transactions in EF 6

    Based on this documentation (which is mostly based on EF but limitations seem to apply anyway):

    There are still some limitations to the TransactionScope approach:

    Requires .NET 4.5.1 or greater to work with asynchronous methods.

    • It cannot be used in cloud scenarios unless you are sure you have one and only one connection (cloud scenarios do not support distributed transactions).
    • It cannot be combined with the Database.UseTransaction() approach of the previous sections.
    • It will throw exceptions if you issue any DDL and have not enabled distributed transactions through the MSDTC Service.

    Advantages of the TransactionScope approach:

    • It will automatically upgrade a local transaction to a distributed transaction if you make more than one connection to a given database or combine a connection to one database with a connection to a different database within the same transaction (note: you must have the MSDTC service configured to allow distributed transactions for this to work).
    • Ease of coding. If you prefer the transaction to be ambient and dealt with implicitly in the background rather than explicitly under you control then the TransactionScope approach may suit you better.

    Being that the first article is no longer supported and the EF 6 article is newer + the comment from @MarcGravell, I assume that the decision comes down to the advantages and disadvantages of the EF 6 article above.

    0 讨论(0)
提交回复
热议问题