Why does EF updates my PK with the same value?

Why does EF updates my PK with the same value?

Postby jowijnant » Tue 16 Oct 2012 14:02

I'm getting an Ora-060 'Deadlock' error in the following situation:

A incoming WCF call is handled in a typical UnitOfWork pattern with a commit at the end of the call. At a certain point in this operation when we have modifications on the entity, we call context.SaveChanges(acceptchanges) to flush all changes to the DB. Then, we modify again those entities and we reach the end of our UnitOfWork and we do the final commit. There we get the deadlock error.

The last sql statement sent to the database is 'UPDATE PEOPLE SET ID = ID WHERE ID=:p0 AND VERSION=:p1'

* Why does Devart/EF generate this statement? I thought this should be avoided at all times.
* According to our DBA updating the PK locks child tables of the PEOPLE table, which is the reason of the deadlock. (obviously, other threads are doing the same stuff in parallel)

I have a workaround: after calling SaveChanges(), I set the people entity's state to modified => EF generates a true update statement (updating all fields but the PK field).
Posts: 1
Joined: Tue 16 Oct 2012 13:48

Re: Why does EF updates my PK with the same value?

Postby Shalex » Fri 19 Oct 2012 16:39

There is the possibility to turn off generation of fake updates for parent entities:
Code: Select all
var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
config.DmlOptions.EmptyUpdates = false;

The OracleEntityProviderConfig class is available in the %ProgramFiles%\Devart\dotConnect\Oracle\Entity\EF4\Devart.Data.Oracle.Entity.dll assembly.

For more information, refer to http://www.devart.com/dotconnect/oracle/docs/?EFProviderConfiguration.html.
Devart Team
Posts: 7531
Joined: Thu 14 Aug 2008 12:44

Return to dotConnect for Oracle