Hi DavidCraig-4984,
According to your description, maybe your context is being shared by multiple requests which means that the entity you're editing has been tracked already.
You can try to detach an object that has been attached to the context via setting the state to Detached.
Code likes below:
Context.Entry(entity).State = EntityState.Detached
If you want to load entities from the database without fully attaching them to the context (without change tracking), you can use AsNoTracking as JaliyaUdagedara saide.
Here are some similar threads you can refer to.
The instance of entity type cannot be tracked because another instance with the same key value for {'Id'} is already being tracked
instance of entity type cannot be tracked because another instance with same key value is tracked
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
I can't share real code, unfortunately. I'm aware of AsNoTracking(), and have used it other places. The issue here is that I'm not accessing the context directly, but rather through a manager class, and while it's possible to modify that class to not track, this has further ramifications.
I guess what I'm really wondering is, is there a way to say 'don't track the FK relationships if the foreign entity doesn't change?'