VS 2015 ASP.NET Web API (EF6) & Xamarin Enable-Migrations fails

前端 未结 2 1669
礼貌的吻别
礼貌的吻别 2021-02-18 23:39

I\'m developing a project that will use ASP.NET Web API as the data service, and a Xamarin portable app as client.

I\'m trying to enable migrations in the web app, but I

相关标签:
2条回答
  • 2021-02-19 00:20

    It seems it's complaining about Using StartUp project 'MyProject.App' but you have already specified the start up project name with -StartupProjectName MyProject.App

    Can you try only:

    Enable-Migrations -enableautomaticmigrations -ContextTypeName MyProject.Models.ApplicationDbContext -ProjectName MyProject -StartupProjectName MyProject.App -Verbose
    

    Make sure that in your start up project config file you have a valid connection string (unless you specify a connection string name in the DbContext constructor, your connection string should be called ApplicationDbContext, like your DbContext, if I remember correctly)


    UPDATE I underestimated the problem. It seems it might be not how you specify the start up project, but the start up project itself. I suggest looking at this answer. Pay special attention, as I was saying before, that the connection string exists in the web or app.config in the start up project and has the right name.

    0 讨论(0)
  • 2021-02-19 00:22

    Well according to this (tested and works), the only way to enable migrations in aspnetcore+ef6 project, is to have the DbContext impl in an external full .NET class library, plus adding a dummy start up project.
    Sucks but works.

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