Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Transaction DbTransaction of Entity Framework

Shulou Source: shulou.com Published: 2022-06-01 04:32:31 10月05日 Update

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 (); / / commit 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 ();}

Tags: Business Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno Shulou Technology Xiaomi Huawei