EntityFramework的事务DbTransaction
成都创新互联公司专注于乳山企业网站建设,响应式网站建设,商城网站制作。乳山网站建设公司,为乳山等地区提供建站服务。全流程按需定制,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务
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(); } } }
文章题目:EntityFramework的事务DbTransaction
链接URL:http://pwwzsj.com/article/poiesd.html