// I have set up a Timestamp in each table and tested it with the de-bugger using a break point, and then changed some data, gone back to continue operation // of my program and a concurrency exception is raised, so everything is set up fine and working so far
// The problem is a user could leave a listview field in edit mode and a record could be changed by somebody else on abnother computer, and when the // original user comes back and finishes puttimng in there new value, the concurrency is not detected because the update method calls back the latest record // to put in the new listview modified details, and this new current Timestamp is used "since somebody else changed the data", and then the context changes // are saved and a concurrency exception is not raised
// The code is below and I presume I have to read back that record before I can add new data to it and then save changes as this seems to be the issue, any // ideas please ?
public static void UpdateEditedOwner(int Id, string Name, string Tel)
{ using (var context = new CustomerPetsEntitiesContainer())
{ var EditedOwner = (from o in context.Owners
where o.Id == Id
select o).FirstOrDefault();
EditedOwner.Name = Name; EditedOwner.Tel = Tel;
try {
context.SaveChanges(); }
catch (Exception) {
MessageBox.Show("Concurrency"); }
} }