Entity Framework Zero Migration Reference

When I get the Add-Migration Entity Framework migration command, I get the following exception:

System.NullReferenceException: Object reference not set to an instance of an object. at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetFileName(Project project, String projectItemName) at System.Data.Entity.Migrations.MigrationsCommands..ctor(Object project, Object startUpProject, String configurationTypeName, String connectionStringName, String connectionString, String connectionProviderName, PSCmdlet cmdlet)

Any insight?

+8
c # migration entity-framework
source share
2 answers

I saw this before when there are several projects in the solution, and the β€œwrong” project is selected as the launch. For example, someone else said that on the MVC3 website on Azure, they had an Azure project as a launch project, not an MVC project. Switching to the MVC project at startup fixed the problem.

Update: This is fixed in EF5-beta2, which is now available on NuGet.

+27
source share

In fact, you can very easily specify the target project in the Package Manager Console when calling any EF command, simply using the correct flags and arguments, for example, considering the ProjectFoo project from a solution with several projects:

  • enable-migrations -projectname projectfoo
  • add-migration "Initial" -projectname projectfoo
  • update-database -projectname projectfoo etc ...

Just like a pie.

0
source share

All Articles