0

I'm having a problem where it seems that EF is remembering the database model for a DbContext class that I deleted. Here is a summary of what happened (all DbContexts made with the "Code First from database" wizard):

  1. Create DbContext, name it MyDbContext
  2. Use MyDbContext, works fine, eventually decide to restructure
  3. Delete the MyDbContext file
  4. Create a new DbContext, name it DifferentDbContext
  5. Use DifferentDbContext, works fine
  6. Rename DifferentDbContext to MyDbContext

Now, it starts throwing the

"The model backing the 'MyDbContext' context has changed..."

Exception. Renaming it back to DifferentDbContext (or any new name) makes it works fine again.

What I have tried:

  • Clean project/solution
  • Uninstall EF, clean project, reinstall EF
  • Restart Visual Studio/computer
  • Search solution and file system for usage of MyDbContext
  • Ensured connection strings are correct

My best guess is that there could be some old auto-generated EF code/cache, but I haven't managed to find anything. Has anyone else seen something like this or have an idea of what could be causing it?

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
Brendan Cain
  • 272
  • 4
  • 11
  • 1
    You may find this helpful https://stackoverflow.com/questions/3600175/the-model-backing-the-database-context-has-changed-since-the-database-was-crea – Salah Akbari May 15 '18 at 20:11
  • Thanks, https://stackoverflow.com/a/43428637/2525568 fixed the issue, but I'm still not sure why it was still looking for these old tables in the first place. – Brendan Cain May 15 '18 at 20:20

0 Answers0