In thread 1 I have :
MyDbContext contextInstance1 = new MyDbContext();
var entity = contextInstance1.EntityDbSet.First();
// Some work with the entity goes here....
And in thread 2 :
//The entity is passed as an argument from thread 1
contextInstance2.EntityDbSet.Attach(entity);
contextInstance2.EntityDbSet.Remove(entity);
And I get the following error :
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
If I remove the Attach() line, I have an error saying that the entity can't be removed before being firstly attached.
I understand what I have to do, but I don't see how to do it in this situation. My issue is that I have no reference to (and no knowledge of) contextInstance1 in the thread2.
Therefore I am looking for a way to detach the object from the 1st context, before attaching it to the other context. If EF knows that an other instance of the context exists, there should be a way to access it, that's what I'm after.