Exemplo n.º 1
0
        protected virtual async Task <object> ExecuteScalar(string cmdText, DbParam[] parameters, CommandType cmdType, bool @async)
        {
            this.CheckDisposed();

            IDbCommand cmd = null;

            try
            {
                List <OutputParameter> outputParameters;
                cmd = this.PrepareCommand(cmdText, parameters, cmdType, out outputParameters);

                DbCommandInterceptionContext <object> dbCommandInterceptionContext = new DbCommandInterceptionContext <object>();

                await this.Activate(@async);

                this.OnScalarExecuting(cmd, dbCommandInterceptionContext);

                object ret;
                try
                {
                    ret = await cmd.ExecuteScalar(@async);
                }
                catch (Exception ex)
                {
                    dbCommandInterceptionContext.Exception = ex;
                    this.OnScalarExecuted(cmd, dbCommandInterceptionContext);

                    throw WrapException(ex);
                }

                dbCommandInterceptionContext.Result = ret;
                this.OnScalarExecuted(cmd, dbCommandInterceptionContext);
                OutputParameter.CallMapValue(outputParameters);

                return(dbCommandInterceptionContext.Result);
            }
            finally
            {
                this.Complete();
                if (cmd != null)
                {
                    cmd.Dispose();
                }
            }
        }
Exemplo n.º 2
0
        public override void Close()
        {
            if (this.PersistedReader.IsClosed)
            {
                return;
            }

            try
            {
                this.PersistedReader.Close();
                this.PersistedReader.Dispose();/* Tips:.NET Core 的 SqlServer 驱动 System.Data.SqlClient(4.1.0) 中,调用 DataReader.Dispose() 方法后才能拿到 Output 参数值,这算是坑爹么?? */
                OutputParameter.CallMapValue(this._outputParameters);
            }
            finally
            {
                this._adoSession.Complete();
            }
        }
Exemplo n.º 3
0
        public int ExecuteNonQuery(string cmdText, DbParam[] parameters, CommandType cmdType)
        {
            this.CheckDisposed();

            IDbCommand cmd = null;

            try
            {
                List <OutputParameter> outputParameters;
                cmd = this.PrepareCommand(cmdText, parameters, cmdType, out outputParameters);

                DbCommandInterceptionContext <int> dbCommandInterceptionContext = new DbCommandInterceptionContext <int>();

                this.Activate();
                this.OnNonQueryExecuting(cmd, dbCommandInterceptionContext);

                int rowsAffected;
                try
                {
                    rowsAffected = cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    dbCommandInterceptionContext.Exception = ex;
                    this.OnNonQueryExecuted(cmd, dbCommandInterceptionContext);

                    throw WrapException(ex);
                }

                dbCommandInterceptionContext.Result = rowsAffected;
                this.OnNonQueryExecuted(cmd, dbCommandInterceptionContext);
                OutputParameter.CallMapValue(outputParameters);

                return(dbCommandInterceptionContext.Result);
            }
            finally
            {
                this.Complete();
                if (cmd != null)
                {
                    cmd.Dispose();
                }
            }
        }