I have a pair of classes which, when updated together as shown below are guaranteed to cause a ChangeConflictException because a trigger on child object table updates a value on the parent object record. I believe I am following the correct procedure for resolving the conflict and resubmitting the update, but upon calling the second db.SubmitChanges (or even if I call db.GetChangeSet()), I get the "an attempt has been made to attach or add an entity that is not new blah blah blah" error.
using (SurveyDB db = new SurveyDB())
{
Parent p = db.Parents.Single(t => t.Id == 1);
p.Children.Add(new Child {...});
p.SomeProperty = "new value";
try
{
db.SubmitChanges();
}
catch (ChangeConflictException e)
{
foreach (ObjectChangeConflict o in db.ChangeConflicts)
o.Resolve(RefreshMode.KeepChanges, true);
db.SubmitChanges(ConflictMode.FailOnFirstConflict);
}
}
Any help greatly appreciated.