Entry state modified even if no property was modified (DbUpdateConcurrencyException)

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
raubv0gel
Posts: 15
Joined: Mon 27 Apr 2020 12:35

Entry state modified even if no property was modified (DbUpdateConcurrencyException)

Post by raubv0gel » Mon 27 Apr 2020 12:58

If I set a property of an entity Album, let’s say Album.Name = "Greatest Hits", but Album.Name == "Greatest Hits" was true before, DbContext.Entry<Album>(Album).State is set to EntityState.Modified. This seems to be wrong, because there is no change.

If I call DbContext.SaveChanges() later, I get an odd DbUpdateConcurrencyException. If you catch this exception, you can compare database values and local values (see https://docs.microsoft.com/en-us/ef/ef6 ... oncurrency). But these values do not differ!

This seems to be a bug. I can try to create a minimal working example if needed.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Entry state modified even if no property was modified (DbUpdateConcurrencyException)

Post by Shalex » Thu 30 Apr 2020 20:32

The issue is caused by change tracking implementation in EF engine. Refer to https://stackoverflow.com/questions/135 ... -is-set-b/.

raubv0gel
Posts: 15
Joined: Mon 27 Apr 2020 12:35

Re: Entry state modified even if no property was modified (DbUpdateConcurrencyException)

Post by raubv0gel » Wed 06 May 2020 11:59

Thank you. That’s strange …

If I set FoundRows = true in a MySqlConnectionStringBuilder instance, I don’t get the exception. Is setting FoundRows the right way / best practice?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Entry state modified even if no property was modified (DbUpdateConcurrencyException)

Post by Shalex » Fri 08 May 2020 11:35

"FoundRows=true;" in the connection string is the right way.
FoundRows specifies whether the provider will return the number of rows matched by the WHERE condition of the UPDATE statement instead of the rows actually changed as the number of changed rows.


Post Reply