0

I'm trying to implement optimistic concurrency, I have a timestamp column with the Concurrency Mode set to fixed. Everything is working as expected, except, when I'm trying to catch the exception it is not going into the expected DbUpdateConcurrencyException catch, instead, it's going into the generic exception catch:

catch (DbUpdateConcurrencyException ex) //Expect the error to be caught here
            {
                ex.Entries.Single().Reload();
                db.SaveChanges();
            }
catch (Exception e) //Error is actually being caught here
            {

            }

The error that is being caught is below:

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

I'm not sure what I need to change to get the exception to be caught by the correct catch

Spitfire5793
  • 391
  • 2
  • 15
  • maybe that can help [Refresh ObjectStateManager entries](https://stackoverflow.com/questions/1836173/entity-framework-store-update-insert-or-delete-statement-affected-an-unexpec) – Rans Mar 10 '20 at 11:35

1 Answers1

0

Found the problem, its an OptimisticConcurrencyException not a DbUpdateConcurrencyException

Spitfire5793
  • 391
  • 2
  • 15