コード例 #1
0
        public IEnumerable <ResultSet> Execute(IDictionary <string, object> suppliedParameters)
        {
            var procedure = _adapter.GetSchema().FindProcedure(_procedureName);

            if (procedure == null)
            {
                throw new UnresolvableObjectException(_procedureName.ToString());
            }

            using (var cn = _adapter.CreateConnection())
                using (var command = cn.CreateCommand())
                {
                    command.CommandText = procedure.QualifiedName;
                    command.CommandType = CommandType.StoredProcedure;
                    SetParameters(procedure, command, suppliedParameters);
                    try
                    {
                        var result = _executeImpl(command);
                        if (command.Parameters.Contains(SimpleReturnParameterName))
                        {
                            suppliedParameters["__ReturnValue"] = command.Parameters.GetValue(SimpleReturnParameterName);
                        }
                        RetrieveOutputParameterValues(procedure, command, suppliedParameters);
                        return(result);
                    }
                    catch (DbException ex)
                    {
                        throw new AdoAdapterException(ex.Message, command);
                    }
                }
        }
コード例 #2
0
        public IEnumerable <ResultSet> Execute(IDictionary <string, object> suppliedParameters, IDbTransaction transaction)
        {
            var procedure = _adapter.GetSchema().FindProcedure(_procedureName);

            if (procedure == null)
            {
                throw new UnresolvableObjectException(_procedureName.ToString(), string.Format("Procedure '{0}' not found.", _procedureName));
            }

            var cn = transaction == null?_adapter.CreateConnection() : transaction.Connection;

            using (cn.MaybeDisposable())
                using (var command = cn.CreateCommand(_adapter.AdoOptions))
                {
                    command.Transaction = transaction;
                    command.CommandText = procedure.QualifiedName;
                    command.CommandType = CommandType.StoredProcedure;
                    SetParameters(procedure, command, suppliedParameters);
                    try
                    {
                        var result = _executeImpl(command);
                        if (command.Parameters.Contains(SimpleReturnParameterName))
                        {
                            suppliedParameters["__ReturnValue"] = command.Parameters.GetValue(SimpleReturnParameterName);
                        }
                        RetrieveOutputParameterValues(procedure, command, suppliedParameters);
                        return(result);
                    }
                    catch (DbException ex)
                    {
                        throw new AdoAdapterException(ex.Message, command, ex);
                    }
                }
        }