Database.BeginTransaction vs Transactions.TransactionScope

c# entity-framework entity-framework-6 transactions transactionscope

Question

What distinguishes the twoSystem.Transactions.TransactionScope both EF6'sDatabase.BeginTransaction ?

Could someone provide a brief illustration or simply explain which one to use when there is a distinct difference?

P.S. I'm using EF6 in my project. Although I've already read the material, it wasn't very helpful. Researched the examples as well, however they are more usingSqlConnection.BeginTransaction and now that MS has released this newDatabase.BeginTransaction in EF6.

1
80
10/21/2016 6:02:54 AM

Accepted Answer

I discovered the solution in the Entity Framework 6 documentation:

Microsoft advises making use of the following new API methods with the release of EF6:Database.BeginTransaction() and Database.UseTransaction() even thoughSystem.Transactions.TransactionScope is still extremely well supported, however for the majority of EF6 users, it is no longer necessary.

While Database.BeginTransaction() is exclusively used for transactions connected to databases,System.Transactions.TransactionScope Additionally, allows "simple C# code" to also be transactional.

hence, utilizeDatabase.BeginTransaction() When using EF6 and simply doing database-related activities in transactions,System.Transactions.TransactionScope for combining C# code with database operations in a single transaction.

Those who continue to favor theTransactionScope manner, it is advised that they look at its drawbacks, particularly in cloud scenarios (cloud scenarios do not support distributed transactions).

You can get more details at here.

91
10/18/2017 9:32:33 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow