Could not load assembly ‘CFMigrationsSyntax.DataLayer’. (If you are using Code First Migrations inside Visual Studio this can happen if the startUp project for your solution does not reference the project that contains your migrations. You can either change the startUp project for your solution or use the -StartUpProjectName parameter.)
Depend on your solution and projects setup in Visual Studio, sometime Entity Framework Code First commands don’t run as expected.
By default, when Code First migration commands run, it will pick the default project set on your Package Manager Console:
But most of the time, we have separate projects in Visual Studio solutions for presentation, business and data layers. EF Code First migration is enabled on the project where your EF Context lives, data layer, while the startup project for the solution is the presentation layer’s project. And since the startup project doesn’t have reference to data layer (where EF is), Package Manager Console will always throw error when running Code First migration commands.
Here’s my typical projects setup:
MainConsole is the presentation and reference to the business layer,
CFMigrationsSyntax.BusinessLayer project. In turn,
CFMigrationsSyntax.BusinessLayer reference to the data layer,
To run EF Code First commands againts the data layer project,
CFMigrationsSyntax.DataLayer, first change the default project in Package Manager Console to your EF project and then add the following parameter to the Code First migration commands:
In my case:
PM> Enable-Migrations -StartUpProjectName CFMigrationsSyntax.DataLayer