I am using Npgsql.EntityFrameworkCore to insert and update records in a table. However every so often it throw the error:
The instance of entity type 'UserAccount' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
Where my table/Entity is UserAccount.
I look at the database and I see that one of the IDs is -2147482647
This happens sporadically and I cannot reproduce or find any documentation on it. I have no errors before the ID is updated, once I update the ID to something appropriate the system runs normally again without the former error.
It seems that -2147482647 is the temporary ID that Entity uses for objects before it SavesChanges. Once it saves the changes it should update that ID to what the Database sequence should be. So when it tries to hold an object as -2147482647 it sees that ID is already in the system and throws the error.
Has anyone had ever had anything like this happen before? I have been troubleshooting it the best I can but without being able to reproduce it I'm just taking shots in the dark.
