Vedi Resolving optimistic concurrency exceptions with Reload (database wins):comprensione Entity Framework concorrenza ottimistica (database WINS) modello
using (var context = new BloggingContext())
{
var blog = context.Blogs.Find(1);
blog.Name = "The New ADO.NET Blog";
bool saveFailed;
do
{
saveFailed = false;
try
{
context.SaveChanges();
}
catch (DbUpdateConcurrencyException ex)
{
saveFailed = true;
// Update the values of the entity that failed to save from the store
ex.Entries.Single().Reload();
}
} while (saveFailed);
}
Perché il metodo SaveChanges()
viene chiamato dopo Reload()
? Questa chiamata non cambierà mai i dati nel database.