Support `UseAffectedRows` option
See original GitHub issueEntity Framework throws DbUpdateConcurrencyException
whenever an Update is run which ‘affects’ 0 rows.
Currently Pomelo implements this library for EntityFramework and selects ROW_COUNT() after updates to find out if a row was impacted, which returns the number of changed rows by default.
When passing a row to Update where no values have actually changed (possible when working RESTfully) , this will return 0 as MySql will automatically not change any data. This throws the exception and causes batch updates to roll back.
Allowing the UseAffectedRows
option on connection strings will open up user configuration, to return the number of rows which WOULD be affected if the Update changed data, instead of the number which were actually updated.
Currently setting this option in the connection string throws NotSupportedException: UseAffectedRows=False is not supported
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (12 by maintainers)
@bgrainger I don’t have useful code sample for debugging right now, but have been planning to put one together as I ran into more serious issues which led to moving onto Postgres. I will be happy to put together a use case if it’s helpful to you.
The basic story right now, is Entity Framework checks the number of rows matched/affected (depending on the provider setup) and throws if it gets back 0. This is to protect data and allow for application recovery when the model in memory falls out of sync with the model on the database. An example of this is if another application has modified that table row since it was loaded - hence DbConcurrencyException
There is some documentation here: https://docs.efproject.net/en/latest/saving/concurrency.html
Ok good to hear EF change tracking isn’t broken. We will implement UseAffectedRows. The second comment is just details on how to implement it.