标签:
1 using (var context = new FcityDB2Entities()) 2 { 3 using (var trasaction = context.Database.BeginTransaction()) 4 { 5 try 6 { 7 TestEF t = new TestEF(); 8 t.username = "conan"; 9 t.age = 101; 10 t.birthday = System.DateTime.Now; 11 context.Set<TestEF>().Add(t); 12 context.SaveChanges(); 13 14 TestEF t2 = new TestEF(); 15 t2.username = "conan"; 16 t2.age = 101; 17 t2.birthday = System.DateTime.Now; 18 context.Set<TestEF>().Add(t2); 19 context.SaveChanges(); 20 trasaction.Commit(); 21 } 22 catch 23 { 24 trasaction.Rollback(); 25 } 26 } 27 }
标签:
原文地址:http://www.cnblogs.com/lyl6796910/p/4672663.html