怎么使用事务操作两条数据库执行语句?

peip12 2018-01-14 10:42:28
为了保证数据的一致性,需要操作两个表的更新动作,怎么使用事务来执行语句?C#
...全文
386 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
全栈极简 2018-01-14
  • 打赏
  • 举报
回复
看下这篇博客中的事务部分的代码:http://www.cnblogs.com/guwei4037/
peip12 2018-01-14
  • 打赏
  • 举报
回复
求大神们的思路。
圣殿骑士18 2018-01-14
  • 打赏
  • 举报
回复
我用EF的例子:
/// <summary>
        /// 删除单件
        /// </summary>
        /// <param name="itemId"></param>
        public void DeleteItem(long itemId)
        {
            using (var context = new AppDbContext())
            using (var trans = new BlTransaction(context, IsolationLevel.ReadCommitted))
            {
                //使用中的单件不允许删除
                var detail = context.ord_in_changedetail.FirstOrDefault(c => c.ItemId == itemId);
                if (detail != null) throw new ShowErrorException("此单件已有出入库记录,不能删除!");

                //删除
                context.ord_ba_item.Where(c => c.ItemId == itemId).Delete();
                context.ord_ba_itemcustom.Where(c => c.ItemId == itemId).Delete();

                trans.Commit();
            }
        }
秋的红果实 2018-01-14
  • 打赏
  • 举报
回复
给你例子 https://www.cnblogs.com/tylerdonet/archive/2013/04/06/3002920.html 其实跟你平时用ado.net写东西差不多,多了几条语句而已 --------------------------------\0

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧