Tag: transactions

如何使用datacontext进行事务处理

我可以使用带有datacontext的事务,以便在出错后可以回滚上下文的状态吗? 如果是这样,那怎么办?

如何在Entity Framework中回滚事务

string[] usersToAdd = new string[] { “asd”, “asdert”, “gasdff6” }; using (Entities context = new Entities()) { foreach (string user in usersToAdd) { context.AddToUsers(new User { Name = user }); } try { context.SaveChanges(); //Exception thrown: user ‘gasdff6’ already exist. } catch (Exception e) { //Roll back all changes including the two previous users. } […]