Alex Rivera | Logout

TransactionScope vs Transaction in LINQ to SQL

Asked 2009-02-12T17:50:23.820
79

What are the differences between the classic transaction pattern in LINQ to SQL like:

using(var context = Domain.Instance.GetContext())
{
    try
    {
        context.Connection.Open();
        context.Transaction = context.Connection.BeginTransaction();
        /*code*/
        context.Transaction.Commit();
    }
    catch
    {
        context.Transaction.Rollback();
    }         
}

vs the TransactionScope object

using (var context = Domain.Instance.GetContext())
using (var scope = new TransactionScope())
{
    try
    {
        /*code*/
        scope.Complete();
    }
    catch
    {
    }
}
Edit
Report

1 Answer

21

One big difference (lesson learnt the hard way) – TransactionScope uses MS DTC for transaction management.

If your application has to manage database transaction only, and no services or remote calls are involved, you can skip the potential issues related to MS DTC by using transaction native to databases (DbTransactions).

answered 2011-10-04T22:52:42.110

Your Answer