I work in a disconnected script, but I noticed that deleting the context of an object does not release attached objects. As a result, subsequent operations often fail.
So, to solve this problem, I myself disable everything when the object context is placed:
public void Dispose()
{
var objectStateEntries =
_context.UnderlyingContext.ObjectStateManager.GetObjectStateEntries(EntityState.Unchanged);
objectStateEntries.ToList().ForEach(o => { if (o.Entity != null)
{
_context.UnderlyingContext.Detach(o.Entity);
}});
_context.Dispose();
_context = null;
}
However, a side effect is that the graph of the object is completely separated, but I really want to keep the graph!
It seems I have not found a solution for this, is it true that this is impossible?
source
share