Null reference on Entity Framework Migration

前端 未结 2 2087
我寻月下人不归
我寻月下人不归 2020-12-20 16:22

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

System.NullReferenceException: Object referen

相关标签:
2条回答
  • 2020-12-20 17:05

    I've seen this before when there are multiple projects in the solution and the "wrong" project is selected as the startup project. For example, somebody else reported that in an Azure hosted MVC3 website they had the Azure project as the startup project instead of the MVC project. Switching over to the MVC project as the startup fixed the issue.

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

    0 讨论(0)
  • 2020-12-20 17:15

    You can actually very easily specify the target project in your Package Manager Console when calling any EF command by just using the correct flags and arguments, for instance, given a project called ProjectFoo out of a solution with multiple projects:

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

    Easy as pie.

    0 讨论(0)
提交回复
热议问题