using (var DBcontext = new EFCoreContext())
// Get the actor from database and change its contact number
var actor = DBcontext.Actors.Single(p => p.ActorID == 1);
actor.ContactNumber = "222-222-2222";
// Change name of the actor in the database to simulate a concurrency conflict
DBcontext.Database.ExecuteSqlRaw(
"UPDATE dbo.Actor SET FName = 'John' WHERE ActorId = 1");
// Save the changes to the database
catch (DbUpdateConcurrencyException ex)
foreach (var item in ex.Entries)
if (item.Entity is Actor)
var currentValues = entry.CurrentValues;
var dbValues = entry.GetDatabaseValues();
foreach (var prop in currentValues.Properties)
var currentValue = currentValues[prop ];
var dbValue = dbValues[prop ];
// Refresh the original values to bypass next concurrency check
item.OriginalValues.SetValues(dbValues);
throw new NotSupportedException( "Donβt know handling of concurrency
conflict " + item.Metadata.Name);