您好,登錄后才能下訂單哦!
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(); // 提交事務 tran.Commit(); } catch (Exception ex) { if (tran != null) { // 事務回滾 tran.Rollback(); Console.WriteLine("事務回滾"); throw ex; } } finally { if (entity != null && entity.Connection.State != ConnectionState.Closed) { entity.Connection.Close(); } } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。