How to make Entity Framework migrations work?

can't make it work entity framework migrations

  • When I executed the command update-database an getting the following error: Update-Database : Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception. At line:1 char:16 + Update-Database <<<< -verbose + CategoryInfo : NotSpecified: (:) [Update-Database], UnintentionalCodeFirstException + FullyQualifiedErrorId : System.Data.Entity.Infrastructure.UnintentionalCodeFirstException,System.Data.Entity.Migrations.UpdateDatabaseCommand What I'm doing wrong??

  • Answer:

    I think the problem is that you are using a Code Generation Template to get you Entity classes from the model. If you want to use EntityFramework.Migrations, you should change your approach to Code First. What you can do is copy all the Entity Classes generated from the T4 template on another folder, delete the model (EDMX) and the other T4 files, and then add the Entity Classes that you backed up before again to your project.

Jorge at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.