I've read a few questions and texts on attachment but they seem to skip some detail on how it works. For example, I don't know why the following happens:
MyContext c = new MyContext(); MyEntity e = new MyEntity(); /* some local edits in e */ c.MyEntity.Add(e); // Works fine
But if I edit it inside a function on another class(which does not create a new instance), I get IEntityChangeTracker exception:
MyContext c = new MyContext(); MyEntity e = new MyEntity(); e = ViewModelClass.SomeFunctionWhichAltersAnExistingEntityInstance(e); c.MyEntity.Add(e); //IEntityChangeTracker "multiple instances" exception
Most answers on this subject say that this happens when an object is attached to multiple contexts.
If this is whats happening, when and why an instance of an entity class becomes automatically attached to a context(and where does this context come from)?
About the Entity version used: RuntimeVersion:v4.0.30319 Version:22.214.171.124