I need to attach EF object (previously detached) to a new ObjectContext. The problem is that I don’t know if it was attached or loaded before. And if there is an object with the same key loaded to ObjectContext I get an exception when I try to attach. Is there a way to check if there is an object with a particular key already attached?
Thanks!
The state of objects inside an object context is managed by the ObjectStateManager.
from MSDN:
Also see: http://msdn.microsoft.com/en-us/library/dd456854.aspx
from previous MSDN link:
.. I suppose that in your case this could be one of the cached item.
Hope it helps!