C# – Linq To Sql – Handle a Transaction Deadlock

When using Linq To SQL, here’s the pattern I use to retry an operation after it failed because a deadlock occured in a SQL Database: while (true) { try { using (var scope = new TransactionScope()) { using (var db = new MyDataContext()) { // Do what you need to do on the DB… db.SubmitChanges(); … Read moreC# – Linq To Sql – Handle a Transaction Deadlock

C# – Linq to Sql – Reattach and Update an entity

If you’d listen to Microsoft, you’d believe than in Linq to SQL, you can’t reattach a changed entity to a new DataContext and submit the changed entity to the database. Well this isn’t true. It can be done with a little bit of foresight. The first step is to make sure that the underlying table … Read moreC# – Linq to Sql – Reattach and Update an entity