Wednesday, March 9, 2016

Entity Framework Migrations: No context type was found in the assembly 'MyProject'

After creating an initial version of my data model using EF Code First, it was time to enable the Code-First migrations. So I opened up the Package Manager console and typed the following command:
Enable-Migrations
Doing that had no effect, instead I got the following error message back:
No context type was found in the assembly 'MyProject'
The problem was that the project where I created the DbContext class was not the same as the project where I wanted to store the migrations. The EF guys were smart and already provided a solution for this. By using the –ContextProjectName option, you can specify the project name(!), this one is important so not the namespace or full name of the context class, where Migrations should search for a context:
Enable-Migrations -ContextProjectName "MyProject.DAL"

No comments: