码迷,mamicode.com
首页 > 其他好文 > 详细

ef 事务

时间:2015-07-24 10:34:03      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

 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             }

 

ef 事务

标签:

原文地址:http://www.cnblogs.com/lyl6796910/p/4672663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!