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)); } } }
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); } } } }
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; } } } }