Search code examples
asp.net-mvc-4entity-framework-5entity-framework-migrations

Enable migrations in class library project


How to enable migrations in a class library project?

I'm building a project using Code First EF5. I want to separate the data and the mvc web project by adding a class library project.

Right now the migrations is enabled in the mvc web project. I'll have to remove that too.

Any ideas?


Solution

  • You should be able to do it using the "Package Manager Console" (View > Other Windows > Package Manager Console).

    Ensure the default project drop down is set to the class library project you want to enable migrations for, ensure you have a reference to the Entity Framework DLL in the project, and then run enable-migrations.

    To run update-database commands etc you'll need an app.config file that includes a connection string for each of your data contexts.