コード例 #1
0
ファイル: DBQuery.cs プロジェクト: Williebwl/learn_framework7
 protected T Do <T>(DBBuilder dbBuilder, Func <IDbConnection, T> fn)
 {
     if (dbBuilder.Transaction != null)
     {
         return(fn(dbBuilder.Transaction.Connection));
     }
     else if (this.Transaction != null)
     {
         return(fn(dbBuilder.SetTransaction(this.Transaction).Transaction.Connection));
     }
     else
     {
         using (var connection = DBAdapter.CreateConnection(this.connection.ConnectionString))
         {
             if (connection.State != ConnectionState.Open)
             {
                 connection.Open();
             }
             T result = fn(connection);
             if (connection.State != ConnectionState.Closed)
             {
                 connection.Close();
             }
             return(result);
         }
     }
 }
コード例 #2
0
ファイル: DBQuery.cs プロジェクト: Williebwl/learn_framework7
        /// <summary>
        /// 创建新连接开启事务
        /// </summary>
        public void Begin(string connectionName = null)
        {
            IDbConnection connection = DBAdapter.CreateConnection(CFConfig.GetConnection(connectionName).ConnectionString);

            connection.Open();
            this.Transaction  = connection.BeginTransaction(IsolationLevel.Serializable);
            disposeConnection = true;
        }