Created
October 17, 2014 17:13
-
-
Save SalihKARAHAN/4df17bbb4616ef28d630 to your computer and use it in GitHub Desktop.
Executer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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