The question is only to undo the changes, not commit.
Let's say I take some data, I change it, I send the changes (optional step) and roll back the transaction. Wherever you look at each author, it discards the changes.
But I found out that this is half the truth - LINQ DataContext will save the changed data! I tested this with TransactionScope and DataContext.Transaction. In both cases, I got the same behavior.
A workaround would be to recreate the DataContext after the rollback (however, this leads to other problems, such as caching data and handling nested transactions) or manually discarding changes to the DataContext. However, these are just workarounds.
Questions
So what am I missing? LINQ to SQL is not suitable for transactions? How to use transactions so that they REALLY revert the changes?
Example
MyTable record = null;
db.Connection.Open();
using (db.Transaction = db.Connection.BeginTransaction())
{
record = db.MyTable.First();
record.BoolField = !record.BoolField;
db.SubmitChanges();
db.Transaction.Rollback();
}
source
share