问题
We are building an app using code-first migrations. We had been using Entity Framework 5.0.0 RC, and we updated our NuGet package for Entity Framework. The database has been in sync with the models context. Code first migrations have been working fine for months.
When we modify our models, and try to add a migration, or even query for migrations, we receive the System.InvalidOperationException for the model backing changed.
Well, obviously it has, I'm trying to add a migration.
We're not sure what to do from here. If I remove the changes, I can run Get-Migrations successfully and it shows that the database has all the migrations applied correctly. Although the ProductVersion column says "5.0.0-rc.net45".
Has anyone else experienced this problem?
回答1:
Found it. The source of this problem was code that set the DbContext.CommandTimeout
in our constructor for the same class, like in this other question. Accessing that property started an initialization process that was giving us the error of what the command we actually invoked was trying to solve.
来源:https://stackoverflow.com/questions/15169281/receiving-the-model-backing-the-context-context-has-changed-on-add-migrati