1

I'm trying to update an object graph that contains ICollection of modified/added/deleted entities in a detached scenario (short lived context), using EF 5.0?

I have something like this:

Visit (Edited)    
    FinancialInfo (Unchanged)
          Discount1 (Added)
          Discount2 (Modified)
          Discount3 (Deleted)

When I try to update visit it throws OptimisticConcurrency exception:

"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."

Actually I know what is causing the problem, but I'm using a repository pattern, I do not use DbContext directly.

I could write custom update logic for Visit entity which would handle the issue, but I'm looking for a generic option.

This makes me think that, probably there's no hustle free approach, but anyway...

Any advice will be appreciated.

Thank you

Community
  • 1
  • 1
pangular
  • 699
  • 7
  • 27

1 Answers1

0

That's how I did this at this point:

I overrided the Update method of my base repository class and wrote custom logic about handling objects in the update tree. I followed this example

I don't like this solution but I hope EF will become more flexible in the near future. Thanks for your attention,.

pangular
  • 699
  • 7
  • 27