Looking into it I verified that for example the value o "myInt" is not rolledback in the following scenario
int myInt = 10;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
myInt=20;
Transaction t = Transaction.Current;
t.Rollback();
}
So it got me thinking "Does a TransactionScope only rollback activities related to the database? Or there are other things that the Transaction can manage and I'm unware of those?"
The TransactionScope class provides a simple way to mark a block of code as participating in a transaction, without requiring you to interact with the transaction itself. A transaction scope can select and manage the ambient transaction automatically.
The ambient transaction is the transaction that is present in the thread that the current application code is executing within. To obtain a reference to the ambient transaction call the static Current property of Transaction: <em>Transaction ambientTransaction = Transaction.Current;</em>
A SQL transaction is a grouping of one or more SQL statements that interact with a database. A transaction in its entirety can commit to a database as a single logical unit or rollback (become undone) as a single logical unit. In SQL, transactions are essential for maintaining database integrity.
Entity Framework is already operating within a TransactionScope. The connection object in the transaction passed is null. That is, the transaction is not associated with a connection – usually this is a sign that that transaction has already completed.
Current transaction affects only specific objects, that are called Resource Managers. Those object must implement specific interfaces to participate in transaction. ADO.NET SqlConnection object is an example. It is not difficult to create an object that works as "Transactional Memory". Those objects are called Volatile Resource Managers. A simple example is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With