我想在 EF 中使用事务。但我对此一无所知。
请将此 ADO 代码转换为 EF:
using System.Data.SqlClient;
private void button4_Click(object sender, EventArgs e)
{
string strConnection = @"Data Source = ARASH-PC\ARASH; Initial Catalog = SampleDB; User Id = sa; Password = 1;";
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand command1 = new SqlCommand("INSERT " + " INTO Acc_Group (SalMali,Code_Group,Name_Group)" + " VALUES(84,60,N'aaaa')", con);
SqlCommand command2 = new SqlCommand("INSERT " + " INTO Acc_Group (SalMali,Code_Group,Name_Group)" + " VALUES(84,80,N'ssss')", con);
SqlTransaction Transaction = con.BeginTransaction();
command1.Transaction = Transaction;
command2.Transaction = Transaction;
command1.ExecuteNonQuery();
command2.ExecuteNonQuery();
Transaction.Save("This Point");
Transaction.Rollback("This Point");
Transaction.Commit();
command1.Dispose();
command2.Dispose();
con.Close();
}
谢谢