650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>
Public static void transaction () { myitentities entity = null; dbtransaction tran = null; try { entity = new myitentities (); entity . Connection.Open (); tran = entity. Connection.begintransaction (); student st = entity. Student.firstordefault (c => c.studentid == 20); st. studentname = "Test"; st. Age = 55; entity. SaveChanges (); // commits the transaction tran. Commit (); } catch (Exception ex) { if (tran != null) { // transaction rollback tran. Rollback (); console.writeline ("Transaction rollback"); throw ex; } } finally { if (entity != null && entity. connection.state != connectionstate.closed) { entity. Connection.close (); } }}
650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>
Transaction dbtransaction of the Entity Framework