How can I receive a transaction as argument in methods parameter?
private void method_A(/*How to receive command-transaction here? */)
{
/* doing tons of db stuff.. */
}
protected void Insert_OnClick(object sender, EventArgs e)
{
//begin transaction
var connection = WhatEverMyConnectionsIs();
using (var transaction = connection.BeginTransaction())
{
try
{
var command = new OldDbCommand();
command.Transaction = transaction;
Method_A(command);
Method_B(command);
Method_C(command);
transaction.Commit();
}
catch(Exception ex)
{
//if there was an exception rollback.
transaction.Rollback();
}
}
}
Also, once I pass the transaction into a methods parameter where I got some db read/insert/update syntax, do I have to do anything specific within the method as well? I have never used a transaction before.