-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API for fully resetting a DbContext (ResetState) #23115
Comments
@roji This was an intentional choice when implementing #15577. I started with the idea of it being a general reset, but it seemed that most people don't really want that. For example, I don't think people will expect (or even want) options they have changed on the context to be reset. Likewise with registered events. I think we could consider doing a full reset (this issue), but I was planning on basing that on feedback. |
OK. Are we sure there's no bug lurking in the fact that we reset the state manager but not the local view? If not then this is indeed just another possible enhancement for the backlog... |
@roji I wrote a bunch of tests. :-) I think its better to think of it not as resetting the state manager, but really just clearing out all tracked entities, as the API name suggests. |
#15577 added ChangeTracker.Clear, which is a faster alternative to mass-detach. However, this is not a full context reset, in the way that DbContext pooling works (ResetState) - other services other than the ChangeTracker aren't reset by this. The main problem with using calling ResetState on a context today, is that this sets _isDisposed to true, and the only way to undispose it goes through DbContextLease which is internal.
I'm noting that DbContext.Reset resets all the InternalDbSets, i.e. the local view, which has some state. Is it OK that we're telling users to reset the ChangeTracker but leaving the local view state untouched?
/cc @ajcvickers
The text was updated successfully, but these errors were encountered: