question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `UseAffectedRows` option

See original GitHub issue

Entity 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:closed
  • Created 7 years ago
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
Nick-Lucascommented, Oct 20, 2016

@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

1reaction
caleblloydcommented, Oct 16, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Hibernate: Enabling useAffectedRows causes ...
I'm assuming this is happening because enabling useAffectedRows causes those types of updates to return a 0 for the row count because nothing ......
Read more >
4.5 Connector/NET Connection Options Reference
This chapter describes the full set of MySQL Connector/NET 8.0 connection options. The protocol you use to make a connection to the server...
Read more >
MySQL .NET Connection String Options
A MySqlConnection is configured using a connection string. The connection string options are key/value pairs described on this page.
Read more >
Add option permit having "affected" or "found" rows
Mysql connector/j have similar problem with rewriteBatchedStatements and useAffectedRows. They have been able to make it work at last for ...
Read more >
6.3.2 Connection
ConnectionLifecycleInterceptor' that should be notified of connection lifecycle events (creation, destruction, commit, rollback, setting the current database ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found