The number of lines to prepare an OracleCommand
object before calling a stored procedure can quickly become redundant and boring. This is how it usually looks like:
var con = new OracleConnection("connection string");
var com = con.CreateCommand();
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "get_employees";
com.CommandTimeout = 60;
I created a simple extension method on the OracleConnection
class that reduces the code to:
var com = con.CreateCommand("get_employees");
Here is the extension method.
public static OracleCommand CreateCommand(
this OracleConnection con,
string commandText,
CommandType commandType = CommandType.StoredProcedure,
int commandTimeout = 60,
bool bindByName = true)
{
var cmd = con.CreateCommand();
cmd.CommandType = commandType;
cmd.CommandText = commandText;
cmd.CommandTimeout = commandTimeout;
// binds the parameters by name.
cmd.BindByName = bindByName;
return cmd;
}