Skip to content

Instantly share code, notes, and snippets.

@SalihKARAHAN
Created October 17, 2014 17:13
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 SalihKARAHAN/4df17bbb4616ef28d630 to your computer and use it in GitHub Desktop.
Save SalihKARAHAN/4df17bbb4616ef28d630 to your computer and use it in GitHub Desktop.
Executer
public virtual TResultType ExecuteQueryEngine<TResultType>(string query, SqlParameter[] parameters, SqlCommand command, Func<TResultType> tryBlock, Action cacthBlock, Action finallyBlock)
{
try
{
if (!string.IsNullOrEmpty(query) && command == null)
{
_sqlCommand = new SqlCommand(query, _sqlConnection, _sqlTransaction);
if (parameters != null)
{
_sqlCommand.Parameters.AddRange(parameters);
}
}
else if (string.IsNullOrEmpty(query) && command != null)
{
_sqlCommand = command;
_sqlCommand.Connection = _sqlConnection;
_sqlCommand.Transaction = _sqlTransaction;
}
else
{
throw new QueryExecutingException("Can not using two way for send query to database!");
}
return tryBlock(); //kodlar user tarafından execte edilir
_sqlTransaction.Commit(); //kullanıcıya kalması acaba kötü mü oldu?
}
catch (DataConnectorException exception)
{
_sqlTransaction.Rollback();
cacthBlock();
throw;
}
finally
{
_sqlCommand.Dispose();
finallyBlock();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment