Support nested transactions
See original GitHub issueHi. Is nesting transactions supported?
I’m trying to implement 2 following scenarios with nested transactions: 1)
var rootTransaction = context.Database.BeginTransaction();
// Add 1st part of data to DB
var innerTransaction = context.Database.BeginTransaction();
// Add 2nd part of data to DB
innerTransaction.Rollback();
rootTransaction.Commit();
In this case all will be ok. In DB will be stored 1st part of data only.
var rootTransaction = context.Database.BeginTransaction();
// Add 1st part of data to DB
var innerTransaction = context.Database.BeginTransaction();
// Add 2nd part of data to DB
innerTransaction.Commit();
rootTransaction.Rollback();
I assume that all data should be removed from DB as I made rollback root transaction. But 2nd part of data still exist in DB.
How to implement nested transactions?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Does SQL Server support nested transactions?
Yes transaction can be nested. But once your outer transaction fails, your inner transaction will be rollback too. Nested transactions in Sql ...
Read more >Nested transactions in CockroachDB 20.1
Nested transactions are invisible to concurrent clients, due to the atomicity and isolation of their surrounding, “outermost” transaction.
Read more >Nested Transactions in SQL Server
In this article I am going to discuss Nested Transactions in SQL Server with Examples. When we put one transaction within another transaction....
Read more >9.2.13. About Nested Transactions JBoss Enterprise ...
Nested Transactions are only supported as part of the Java Transaction Service (JTS) API, and not part of the Java Transaction API (JTA)....
Read more >Nested Transactions
A nested transaction occurs when a new transaction is started on a session that is already inside the scope of an existing transaction....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Kind of mixed on this – nested transactions can be really useful. Mostly for automated tests. I like setting up a database in a state, starting a transaction, running a test, then rolling it back. Makes integration tests really nice.
But some of our more complex stuff uses transactions itself, then it explodes due to nested transactions.
Pondering if I have other options but a nested transaction would make this work really well.
Implicit transactions sort of work, but there are times we may read a few pieces of work then writing to the database, and we don’t want a race conditions between the read/write cycle.
I understand the annoyance of various database engines having spotty support for this if any.
Thanks @ajcvickers for your reply Just to give you more context, in the following code i am assuming that for-each will be executed twice: -first loop will be executed successfully and commit the inner transaction. -second loop will fail and Rollback the inner transaction.
I am expected to find the added rows by the first transaction before rollback the outer transaction but looks like what is happening is rolling back second loop will roll back also first loop
looks like using BeginTransaction within TransactionScope has some issues in addition to the issues with nested transaction in EF6
Any thoughts on this? FYI: there is another post that is reporting the same issue : [http://stackoverflow.com/questions/36396570/using-transactionscope-and-ef-transactions]