Question

My Project has 3 tiers:

  • Project.Core: Entities and Repositories Interfaces.
  • Project.Data: DbContext, Repositories implementation and UnitOfWork implementation. Has reference of Core.
  • Project.UI: Views, Controllers, ViewModels. Has reference of Code and Data.

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'.

Was it helpful?

Solution

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

OTHER TIPS

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

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top