[Solved] An entity object cannot be referenced by multiple instances of IEntityChangeTracker. On multiple entries


Ultimately, this is the same problem mentioned here: How can I use EF to add multiple child entities to an object when the child has an identity key?

If you have a auto generated PK and attempt to do an Add after doing a previous udpate/delete on the same context, it will crash because you end up with the same PKs for multiple objects at the same time.

To fix this, you must either set all those WorkIds (I assume this is the PK) to -1, -2, -3 and their proper FK references to those new numbers
OR
You must add all new entities first before you do any updates/deletes since EF will realize that those IDs will be set in the future.

3

solved An entity object cannot be referenced by multiple instances of IEntityChangeTracker. On multiple entries