3

I am using EF6 and GraphDiff 2.0.1. I want to check for DbUpdateConcurrencyException when I save an outdated entry. When I do this without an UpdateGraph: no problem, EF raises the exception.

try
{
    var dbEntry = Context.Persons.SingleOrDefault(p => p.PersonId == 
        disconnectedEntry.PersonId);
    dbEntry.Name = disconnectedEntry.Name;
    Context.Entry(dbEntry).OriginalValues["RowVersion"] = disconnectedEntry.RowVersion;
    DbContext.SaveChanges();
}
catch (DbUpdateConcurrencyException ex)
{
    // Exception thrown as expected.
}

I used the solution described here to achieve this: EF not throwing DbUpdateConcurrencyException despite conflicting updates

The problem is: if I use an UpdateGraph from GraphDiff before the SaveChanges from EF: UpdateGraph raises an incomplete DbUpdateConcurrencyException. Indeed, the exception doesn't contain Entries.

try
{
    DbContext.UpdateGraph(disconnectedEntry);
    DbContext.SaveChanges();
}
catch (DbUpdateConcurrencyException ex)
{
    // Exception thrown as expected. But ex is incomplete
}

I am surprised that UpdateGraph raises this exception. According to me, UpdateGraph updates the connected entry, but doesn't save. So, it should do nothing and let EF do the job.

Is there a way to avoid that UpdateGraph raises the exception. At least, it could be great if it raises a complete one.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.