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

What to do with tracked entities when database is deleted #18103

Closed
smitpatel opened this issue Sep 27, 2019 · 3 comments
Closed

What to do with tracked entities when database is deleted #18103

smitpatel opened this issue Sep 27, 2019 · 3 comments

Comments

@smitpatel
Copy link
Member

Repro is in #6872 (comment)

We add an entity, save it to database. Now entity is in change tracker.
Then database is recreated with EnsureDeleted/EnsureCreated
Same entity cannot be added again since it is still tracked.

@ardalis
Copy link

ardalis commented Sep 27, 2019

In particular, if in a test scenario you add one entity to an empty database, then delete the database, then add another new entity, it blows up (using InMemory). Because both are assigned ID 1, which is being tracked.

@smitpatel
Copy link
Member Author

We decided in triage that this is by design. If you delete your database in the middle of processing then your DbContext may not be usable. It would be fine pattern to initialize new DbContext or recreate database at very start of processing.

@ardalis
Copy link

ardalis commented Sep 27, 2019

Fair enough, thanks.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants