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.
}
O forse questo viene fatto automaticamente, nel senso che se si verifica un errore, le modifiche di commit vengono annullate per tutte le modifiche. è?Come eseguire il rollback di una transazione in Entity Framework
sì, questo è corretto –