FirstName = "Scott";
267
Part III: LINQ to SQL
con.LastName = "Klein";
con.MiddleName = "L";
con.NameStyle = 0;
con.EmailPromotion = 1;
con.EmailAddress = "ScottKlein@SqlXml.com";
con.PasswordHash = "asdf";
con.PasswordSalt = "qwer";
con.Title = "Geek";
db.Contacts.Add(con);
Contact con1 = new Contact();
con1.FirstName = "Horacio";
con1.LastName = "Hornblower";
con1.MiddleName = "T";
con1.NameStyle = 0;
con1.EmailPromotion = 1;
con1.EmailAddress = "Hornblower@sailingrus.com";
con1.PasswordHash = "asdf";
con1.PasswordSalt = "qwer";
con1.Title = "Captain";
db.Contacts.Add(con1);
db.SubmitChanges();
textBox1.Text = "Transaction Successful!";
ts.Complete();
ts.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Next is an example of an explicit local transaction. Here, the specific transaction connection is created
and controlled, as well as the need to specifically commit and/or roll back the transaction. Like the first
example, the SubmitChanges method is called and executed within the same transaction scope:
db.
Pages:
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432