0

I am writing a small application in C# using Linq2SQL and because of the data this application will be updating and deleting I would like perform the queries much like you can within SSMS where you have a Begin Transaction in the beginning and a Rollback after the queries. Is this possible with Linq2SQL?

This is a sample of one of my updates:

        public static void eoeinfo(Form1.emaildup _ed, Int32 _mainID)
        {
            using (ipamDataContext _db = new ipamDataContext())
            {
                var _records = (from a in _db.WebEOEInfos
                                join b in _db.WebPersonalInfos on a.UserID equals b.UserID
                                where b.Email == _ed.email && b.UserID != _mainID
                                select a).ToList();
                foreach (WebEOEInfo _i in _records)
                    _i.UserID = _mainID;
                try
                {_db.SubmitChanges();}
                catch (Exception e)
                {
                    String _cc = String.Empty;
                    foreach (object _i in _db.ChangeConflicts)
                    {_cc += _i.ToString() + " || ";}
                    Console.WriteLine(_cc);
                }
            }
        }
mattgcon
  • 4,768
  • 19
  • 69
  • 117

1 Answers1

0

Well, the good news is you already are using a transaction.

Because you execute only 1 db.SubmitChanges, L2S will wrap all the update statments resulting from it in a transaction.

Pleun
  • 8,856
  • 2
  • 30
  • 50