Say I get an object through a DbContext and then close that context. Later on I want to get some children of this object and I open a new context. Are there any problems with reattaching the object to the new context that I should be aware of?
Share
If you detach the object from the first context before you dispose it you should have no trouble. If you don’t do that you can in some circumstances receive error that object is already tracked by another context and in such case it is impossible to attach the object to the new context or detach it from the old context (because it is already disposed).
Beware that detaching breaks all relationships. If you want to avoid detaching at all don’t use dynamic proxies created by EF (lazy loading and dynamic change tracking).