class Program { static void Main(string[] args) { using (var ctx = new Jason_TestEntities()) { using (System.Data.Entity.DbContextTransaction dbTran = ctx.Database.BeginTransaction()) { try { ctx.Database.Log = Console.Write; ctx.wolf_example.Add(new wolf_example() { Name = "FirstOrDefault3" }); ctx.wolf_example.Add(new wolf_example() { Name = "FirstOrDefault3" }); ctx.Database.ExecuteSqlCommand("INSERT wolf_example(Name,IsShow)VALUES(N'sqlcmd',2)"); ctx.SaveChanges(); //提交事务 dbTran.Commit(); } catch (Exception ex) { //回滚 dbTran.Rollback(); } } Console.ReadKey(); } } }