static void Transaction() { var customer = new Customer { Name = "好久不见" }; try { // 测试事务 dbContext.BeginTransaction(); dbContext.Customer.Insert.Add(customer); List <Customer> li = new List <Customer> { new Customer { Name = "test" } }; dbContext.Customer.Insert.AddRange(li).SaveChange(); dbContext.Customer.Update.SetValue(a => a.Name, "12345").Where(f => f.Id == customer.Id).SaveChange(); dbContext.CommitTransaction(); ArticleService articleService = new ArticleService(dbContext); var art = articleService.Detail(13); if (art != null) { art = articleService.Update(art.Id, "修改了标题", art.Content); bool success = articleService.Delete(art.Id); } } catch (Exception e) { Console.WriteLine(e.Message); } }