This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I don't seem to be able to get transactions to work. Even when an exception occurs within the TransactionScope block, the changes appear in the database. My code is based on the following example: try
{
using (var transactionScope = new TransactionScope()) Global.UnitOfWork.SaveChanges(); } catch { ... etc ...} Could this have something to do with the fact that I use (and re-use) a global unit of work (based on a UnitOfWorkScopeBase<UnitOfWork> request scope? |
|
|
If you are reusing the same unit of work instance, then it will "accumulate" changes -- that is, if an exception occurs during SaveChanges, the pending changes remain pending, and will be included in the next SaveChanges. So that is one way that changes could be being saved even after a transaction is backed out. If this is the case, you may want to reconsider reusing the UOW in this way. For example, in a Web application we recommend a "session per request" (i.e. a separate UOW for each HTTP request) strategy as encapsulated in the PerRequestUnitOfWorkScope class. Another possibility is that some databases do not respect System.Transactions ambient transactions. What database are you using? You may need to call IUnitOfWork.BeginTransaction() to force an ADO.NET transaction instead. If neither of these helps could you put together a small, complete project that demonstrates the problem and we will investigate further? Thanks! |
|
|
I am using "session per request". My database is MySQL. I'll try to put together a small testcase. |
|