weldsonandrade
weldsonandrade

Reputation: 626

Asp.net MVC 4 How to enable Migrations from DbContext in another Project?

My Project has 3 tiers:

I'm using MVC 4 with Entity Framework 5 and Code First Approach.

So It's possible to enable POCOs Migrations on Project.UI?

I Tried run:

enable-migrations Project.Data.MyDbContext

But receive the message:

The context type 'Project.Data.MyDbContext' was not found in the assembly 'Project.UI'.

Upvotes: 0

Views: 2249

Answers (3)

CShark
CShark

Reputation: 2221

I would suggest that you create a separate project within your solution for data seeding. You can then include a reference to your Project.Data.DLL within the seeding project and run the migrations from there (which would be fitting).

Upvotes: 0

user2367369
user2367369

Reputation: 18

You can also include the Project.Data.DLL to the Project.ui this is the approach we have taken. We have also wrapped views into a similar DLL for use across multiple projects

Upvotes: 0

undefined
undefined

Reputation: 34248

You need to make sure you are running enable-migrations on the project containing your DBContext so you cant run it on the UI project (otherwise it needs to be a relative path to the project from the currently selected one eg. ./project.data)

enter image description here

Set default project to Project.Data

then run:

enable-migrations

Upvotes: 4

Related Questions