6
Resolving optimistic concurrency exceptions with Reload (database wins) देखें:समझना इकाई की रूपरेखा आशावादी संगामिति (डेटाबेस जीतता) पैटर्न
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);
}
क्यों विधि SaveChanges()
Reload()
के बाद कहा जाता है? यह कॉल डेटाबेस में डेटा को कभी भी नहीं बदलेगा।