Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created June 20, 2011 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/1036141 to your computer and use it in GitHub Desktop.
Save einarwh/1036141 to your computer and use it in GitHub Desktop.
Dry data: Main execute method
public TResult Execute<T, TResult>(string spName,
DbParameter[] sqlParams, Func<IDbCommand, T> execute,
Func<T, TResult> map)
{
using (var conn = _dpf.CreateConnection())
using (var cmd = _dpf.CreateCommand())
{
conn.ConnectionString = _connStr;
conn.Open();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName;
cmd.Parameters.AddRange(sqlParams);
cmd.CommandType = CommandType.StoredProcedure;
return map(execute(cmd));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment