利用数据库链接进行事务操作
var db = ConnectionHelper.GetConn(ConnectionType.Write);//获取上下文 var conn = db.Connection;//取出数据库链接 conn.Open();//打开链接 using (var trans = conn.BeginTransaction()) 开启事务 { ServiceStationEntities db = null; db = new ServiceStationEntities((EntityConnection)conn); //然后操作吧 trans.Commit(); }
时间: 2024-10-09 14:44:31