zoukankan      html  css  js  c++  java
  • C# 事务提交(非数据库)

    .Net 2.0开始支持

    static void Main(string[] args)
    {
      using (TransactionScope ts = new TransactionScope())
      {
        UserBLL u = new UserBLL();
        TeacherBLL t = new TeacherBLL();
        u.ADD();
        t.ADD();
        ts.Complete();
      }
    }

    获取事务ID

    Transaction.Current.TransactionInformation.LocalIdentifier

    嵌套事务

    static void Main(string[] args)
    {
        using (TransactionScope ts = new TransactionScope())
        {
            Console.WriteLine(Transaction.Current.TransactionInformation.LocalIdentifier);
            UserBLL u = new UserBLL();
            TeacherBLL t = new TeacherBLL();
            u.ADD();
            using (TransactionScope ts2 = new TransactionScope(TransactionScopeOption.Required))
            {
                Console.WriteLine(Transaction.Current.TransactionInformation.LocalIdentifier);
                t.ADD();
                ts2.Complete();
            }
            ts.Complete();
            }
         }
    }
    1、使用嵌套事务时,默认
    TransactionScopeOption的属性为Required

    2、如果把TransactionScopeOption设为RequiresNew,则嵌套的事务块和外层的事务块各自独立,互不影响

    3、
    TransactionScopeOption设为Suppress则为取消当前区块的事务,一般很少使用。
  • 相关阅读:
    POJ 3279 Fliptile 枚举+搜索
    POJ 3278 Catch That Cow
    CS Academy Round41 BFS+DFS
    CS Academy Round41 Tennis Tournament
    CS Academy Round41 Cinema Seats
    POJ 1177 Picture
    HDU 1255 覆盖的面积
    POJ 1151 Atlantis 线段树+离散化
    HDU 4614 Vases and Flowers 线段树+二分
    凑数问题
  • 原文地址:https://www.cnblogs.com/chengeng/p/3181170.html
Copyright © 2011-2022 走看看