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?
The context class is a most important class while working with EF 6 or EF Core. It represent a session with the underlying database using which you can perform CRUD (Create, Read, Update, Delete) operations. The context class in Entity Framework is a class which derives from System.
Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.
From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure Migrations.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With