我想问在 ADO.Net Entity Framework (call,rollback,commit) 中使用事务的正确方法是什么?我有这段代码,但这给了我例外
"Invalid operation. The connection is closed."
(在此代码中 NorthwindEntities 继承“DBContext”)
NorthwindEntities context = new NorthwindEntities();
DbTransaction tran = context.Database.Connection.BeginTransaction();
var cust = context.Customers.FirstOrDefault(x => x.CustomerID == "BOLID");
cust.Country = "Nigeria";
context.SaveChanges();
tran.Rollback();