Exemple #1
0
        //------Extend Methods----------

        #region 获取事务支持的对象


#if lang_zh
        /// <summary>
        /// 获取事务支持的对象<para />
        /// ( 成功执行的最后,请调用MarkSuccess(),事务结束前会自动Commit;发生错误或者不显式MarkSuccess()的情况下,均会自动Rollback所有修改 )
        /// </summary>
        /// <param name="IsolationLevel">隔离等级</param>
        /// <param name="ConnectionAliasName">连接别名;如果没起别名,则使用默认的连接字符串</param>
#else
        /// <summary>
        /// Get new MicroDBTransaction Object with the Transaction support<para />
        /// ( when transaction is success,call MarkSuccess() method at last,then the transaction will automatically COMMIT; when some exception is happend then case the code NOT to call MarkSuccess() method,  the transaction will automatically Rollback )
        /// </summary>
        /// <param name="IsolationLevel">Level of Isolation</param>
        /// <param name="ConnectionAliasName">the Alias Name of Connection (if not pass name,it will use the DEFAULT name instead.)</param>
#endif

        public static MicroDBTransaction UseTransaction(IsolationLevel IsolationLevel, string ConnectionAliasName = ALIAS_NAME_DEFAULT)
        {
            MicroDBTransaction result = new MicroDBTransaction(IsolationLevel, ConnectionAliasName);

            bool ready = result.MakeReady();

            if (ready == false)
            {
#if lang_zh
                const string errMsg = "数据库连接打开失败!";
#else
                const string errMsg = "DB connection open faild!";
#endif

                throw new InvalidOperationException(errMsg);
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 异步执行
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">使用指定的事务处理</param>
        /// <param name="commandType">SQL语句 | 存储过程</param>
        /// <returns>受影响行数</returns>
#else
        /// <summary>
        /// async ExecuteNonQuery
        /// </summary>
        /// <param name="commandText">SQL statement</param>
        /// <param name="commandParameters">SqlParameter Collection</param>
        /// <param name="transaction">transaction</param>
        /// <param name="commandType">Text | StoredProcedure</param>
        /// <returns>the affected rows</returns>
#endif
        public static async Task <int> ExecuteNonQueryAsync(string commandText, SqlParameter[] commandParameters, MicroDBTransaction transaction, CommandType commandType = CommandType.Text)
        {
            if (transaction == null)
            {
                throw new InvalidOperationException(ERRMSG_TRANSACTION_IS_NULL, new ArgumentNullException("transaction"));
            }

            return(await AsyncSQLHelper.ExecuteNonQueryAsync(transaction.tran, commandType, commandText, commandParameters));
        }
Exemple #3
0
        /// <summary>
        /// 查询,返回单一结果
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">使用指定的事务处理</param>
        /// <param name="commandType">SQL语句 | 存储过程</param>
        /// <returns>单一结果</returns>
#else
        /// <summary>
        /// Query,Get result of One Object
        /// </summary>
        /// <param name="commandText">SQL statement</param>
        /// <param name="commandParameters">SqlParameter Collection</param>
        /// <param name="transaction">transaction</param>
        /// <param name="commandType">Text | StoredProcedure</param>
        /// <returns>Object</returns>
#endif
        public static object ExecuteScalar(string commandText, SqlParameter[] commandParameters, MicroDBTransaction transaction, CommandType commandType = CommandType.Text)
        {
            return(SyncSQLHelper.ExecuteScalar(transaction.tran, commandType, commandText, commandParameters));
        }
Exemple #4
0
        /// <summary>
        /// 异步查询,返回DataTable结果集
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">使用指定的事务处理</param>
        /// <param name="commandType">SQL语句 | 存储过程</param>
        /// <returns>DataTable结果集</returns>
#else
        /// <summary>
        /// async Query,Get result of DataTable
        /// </summary>
        /// <param name="commandText">SQL statement</param>
        /// <param name="commandParameters">SqlParameter Collection</param>
        /// <param name="transaction">transaction</param>
        /// <param name="commandType">Text | StoredProcedure</param>
        /// <returns>DataTable</returns>
#endif
        public static async Task <DataTable> ExecuteDataTableAsync(string commandText, SqlParameter[] commandParameters, MicroDBTransaction transaction, CommandType commandType = CommandType.Text)
        {
            DataSet ds = await ExecuteDataSetAsync(commandText, commandParameters, transaction, commandType);

            //返回结果
            if (ds == null || ds.Tables == null || ds.Tables.Count <= 0)
            {
                return(null);
            }
            return(ds.Tables[0]);
        }
Exemple #5
0
        /// <summary>
        /// 异步查询,返回DataSet结果集
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">使用指定的事务处理</param>
        /// <param name="commandType">SQL语句 | 存储过程</param>
        /// <returns>DataSet结果集</returns>
#else
        /// <summary>
        /// async Query,Get result of DataSet
        /// </summary>
        /// <param name="commandText">SQL statement</param>
        /// <param name="commandParameters">SqlParameter Collection</param>
        /// <param name="transaction">transaction</param>
        /// <param name="commandType">Text | StoredProcedure</param>
        /// <returns>DataSet</returns>
#endif
        public static async Task <DataSet> ExecuteDataSetAsync(string commandText, SqlParameter[] commandParameters, MicroDBTransaction transaction, CommandType commandType = CommandType.Text)
        {
            DataSet ds = await AsyncSQLHelper.ExecuteDatasetAsync(transaction.tran, commandType, commandText, commandParameters);

            return(ds);
        }
Exemple #6
0
        //------DB Operate Methods------

        #region 查询,返回DataSet结果集

#if lang_zh
        /// <summary>
        /// 查询,返回DataSet结果集
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">使用指定的事务处理</param>
        /// <param name="commandType">SQL语句 | 存储过程</param>
        /// <returns>DataSet结果集</returns>
#else
        /// <summary>
        /// Query,Get result of DataSet
        /// </summary>
        /// <param name="commandText">SQL statement</param>
        /// <param name="commandParameters">SqlParameter Collection</param>
        /// <param name="transaction">transaction</param>
        /// <param name="commandType">Text | StoredProcedure</param>
        /// <returns>DataSet</returns>
#endif
        public static DataSet ExecuteDataSet(string commandText, SqlParameter[] commandParameters, MicroDBTransaction transaction, CommandType commandType = CommandType.Text)
        {
            DataSet ds = SyncSQLHelper.ExecuteDataset(transaction.tran, commandType, commandText, commandParameters);

            return(ds);
        }
Exemple #7
0
        //------DB Operate Methods------

        #region 查询,返回DataTable结果集

#if lang_zh
        /// <summary>
        /// 查询,返回DataTable结果集
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="commandParameters">参数集合</param>
        /// <param name="transaction">使用指定的事务处理</param>
        /// <param name="commandType">SQL语句 | 存储过程</param>
        /// <returns>DataTable结果集</returns>
#else
        /// <summary>
        /// Query,Get result of DataTable
        /// </summary>
        /// <param name="commandText">SQL statement</param>
        /// <param name="commandParameters">SqlParameter Collection</param>
        /// <param name="transaction">transaction</param>
        /// <param name="commandType">Text | StoredProcedure</param>
        /// <returns>DataTable</returns>
#endif
        public static DataTable ExecuteDataTable(string commandText, SqlParameter[] commandParameters, MicroDBTransaction transaction, CommandType commandType = CommandType.Text)
        {
            DataSet ds = SyncSQLHelper.ExecuteDataset(transaction.tran, commandType, commandText, commandParameters);

            //返回结果
            if (ds == null || ds.Tables == null || ds.Tables.Count <= 0)
            {
                return(null);
            }
            return(ds.Tables[0]);
        }