MYSQL 是否支持 TransactionScope 而无需将 MySqlConnection 对象作为参数传递?或者它只适用于 MS SQL 2008 及更高版本?
例如:
public void Method()
{
using (var scope = new System.Transactions.TransactionScope())
{
Delete();
Insert();
Update();
scope.Complete();
}
}
public void Update()
{
using(MySqlConnection conn = new MySqlConnection())
{
// Update something in the Database
}
}
public void Insert()
{
using(MySqlConnection conn = new MySqlConnection())
{
// Insert something in the Database
}
}
public void Delete()
{
using(MySqlConnection conn = new MySqlConnection())
{
// Delete something from Database
}
}
或者我应该使用 MySqlConnection conn 对象作为参数吗?
public void Method()
{
using (var scope = new System.Transactions.TransactionScope())
{
using(MySqlConnection conn = new MySqlConnection())
{
Delete(conn);
Insert(conn);
Update(conn);
}
scope.Complete();
}
}
public void Update(MysqlConnection conn)
{
// Update something in the Database
}
public void Insert(MysqlConnection conn)
{
// Insert something in the Database
}
public void Delete(MysqlConnection conn)
{
// Delete something from Database
}