ef中使用事务
2015-08-10 17:25
253 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Transactions; namespace 事务 { class Program { static void Main(string[] args) { MVC5Entities db = new MVC5Entities(); using (var transaction = db.Database.BeginTransaction()) { try { db.Actions.Add(new Action { ActionName = "aaa", AreaName = "aaa", ControllerName = "aaa", FatherID = 0 }); db.SaveChanges(); int a = 0; int b = 10 / a; transaction.Commit(); } catch (Exception e) { Console.WriteLine(e.Message); } } using (TransactionScope scope = new TransactionScope()) { try { db.Actions.Add(new Action { ActionName = "bbb", AreaName = "bbb", ControllerName = "bbb", FatherID = 0 }); db.SaveChanges(); int a = 0; int b = 10 / a; scope.Complete(); } catch (Exception e) { Console.WriteLine(e.Message); } } Console.WriteLine("ok"); } } }
相关文章推荐
- POJ 2112 Optimal Milking(Floyd+多重匹配+二分枚举)
- iOS新特性
- 返回两个日期之间的日期集合
- Jenkins安装配置
- Linux系统下的用户审计方法
- CentOS下安装配置PPTP ***服务器
- C#实现获取程序路径方法小结
- sql查询优化小结
- python 基础教程
- hdu 2025 查找最大元素
- 如何选择redis和memcache
- WPF ListView展示层叠信息
- 学习zepto.js(原型方法)[1]
- 获取某年的某月有多少天
- POJ 2289 Jamie's Contact Groups(多重匹配+二分)
- 人物角色群体攻击判定(三)Physics.OverlapSphere(群体攻击)
- 年度催泪之作:2015中国程序员生存报告
- UML简介
- 对称加密----AES和DES加密、解密
- JAVA -- 设计模式