1 //必须打开连接,用于事务的创建 2 if (db.Connection.State == ConnectionState.Closed) db.Connection.Open(); 3 using (DbTransaction dbtran = db.Connection.BeginTransaction()) 4 { 5 try 6 { 7 db.Transaction = dbtran; 8 db.SubmitChanges(); 9 dbtran.Commit();//提交事务 10 } 11 catch (Exception ex) 12 { 13 dbtran.Rollback();//回滚事务 14 } 15 }View Code
标签:DataContext,dbtran,db,事务,Connection,Code,使用 From: https://www.cnblogs.com/wzf-Learning/p/16630498.html