Yustme
Yustme

Reputation: 6255

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?

Upvotes: 7

Views: 6901

Answers (2)

Artem Vertiy
Artem Vertiy

Reputation: 1118

in many EF articles they mentioned Enable-Migrations command but no example with parameters simply specify project name where your db context and target web project or console program where config with connection string defined:

Package manager console Enable-Migrations -ProjectName "MyApp.Data.Library" -StartUpProjectName "MyApp"

Upvotes: 0

greg84
greg84

Reputation: 7599

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.

Upvotes: 10

Related Questions