Example #1
0
 public int ExecuteNonQuery(string sql, object parameters)
 {
     using (var connection = CreateConnection()) {
         using (var cmd = connection.CreateCommand()) {
             var db = new DatabaseInTx(cmd);
             return(db.ExecuteNonQuery(sql, parameters));
         }
     }
 }
Example #2
0
 public IEnumerable <T> ExecuteReader <T>(string sql, object parameters, Func <DbDataReader, T> action)
 {
     using (var connection = CreateConnection()) {
         using (var cmd = connection.CreateCommand()) {
             var db = new DatabaseInTx(cmd);
             foreach (var item in db.ExecuteReader(sql, parameters, action))
             {
                 yield return(item);
             }
         }
     }
 }
Example #3
0
 public void ExecuteTransaction(Action <IDatabase> action)
 {
     using (var connection = CreateConnection()) {
         using (var transaction = connection.BeginTransaction()) {
             try {
                 using (var cmd = connection.CreateCommand()) {
                     cmd.Transaction = transaction;
                     var db = new DatabaseInTx(cmd);
                     db.ExecuteTransaction(action);
                 }
                 transaction.Commit();
             }
             catch {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }