There are two ways in DLinq to work with Transactions. One is preferred to another.
1. Using the TransactionScope class - Preferred One
using(TransactionScope ts = new TransactionScope()) {
db.SubmitChanges();
ts.Complete();
}
2. Using the BeginTransaction on the SqlConnection
Product prod = q.Single(p => p.ProductId == 15);
if (prod.UnitsInStock > 0)
prod.UnitsInStock--;
db.Transaction = db.Connection.BeginTransaction();
try {
db.SubmitChanges();
db.Transaction.Commit();
}
catch {
db.Transaction.Rollback();
throw;
}
finally {
db.Transaction = null;
}
Hope this helps,
Regards
Tags: DLinq, Linq