Skip to content
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

Implement ChangeTracker.Clear() to stop tracking all entities #21169

Merged
merged 1 commit into from
Jun 8, 2020

Conversation

ajcvickers
Copy link
Member

Fixes #15577

This is an alternative to mass-detach for situations where creating a new context instance is difficult.

The context configuration is not reset, since it seems likely that setting like lazy-loading and registered events are more useful left as they would be--just as is the case when doing mass-detach.

@ajcvickers ajcvickers requested a review from a team June 7, 2020 22:34
Fixes #15577

This is an alternative to mass-detach for situations where creating a new context instance is difficult.

The context configuration is not reset, since it seems likely that setting like lazy-loading and registered events are more useful left as they would be--just as is the case when doing mass-detach.
@ajcvickers
Copy link
Member Author

/cc @JonPSmith - replacement for mass-detach.

@ajcvickers ajcvickers merged commit ebc00e3 into master Jun 8, 2020
@ajcvickers ajcvickers deleted the JustLikeBricksDont0607 branch June 8, 2020 20:42
@JonPSmith
Copy link

Thanks @ajcvickers.

I think this will be very useful in unit tests to simulate a disconnected update etc. Going to be much easier to add, which means it will be used more. Even I sometimes forget (or I'm in a rush to get it done) to separate the data setup stage from the test stage and therefore get incorrect test results.

/// <para>
/// This method should always be preferred over detaching every tracked entity.
/// Detaching entities is a slow process that may have side effects.
/// This method is much more efficient at clearing all tracked entities from the context.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might also want to mention that it doesn't trigger the state changed event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose public API to reset a state of DbContext instance
3 participants