如何在methods参数中接收事务作为参数?
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();
}
}
}
此外,一旦我将事务传递给一个方法参数,在那里我得到了一些db read / insert / update语法,我是否还必须在方法中做任何特定的事情?我之前从未使用过交易。