Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
Contact con = new Contact();
con.FirstName = "Scott";
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);
268
Chapter 13: More about Entity Classes
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!";
db.Transaction.Commit();
db.Transaction.Dispose();
db.Connection.Close();
The TransactionScope class lets you ??????bracket??™??™ your submissions to the database. ??????Bracketing??™??™ means
to make a block of code transactional. The TransactionScope class makes it easy to ??????bracket.
Pages:
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433