Entity Framework Core: DbContextOptionsBuilder does not contain a definition for 'usesqlserver' and no extension method 'usesqlserver'

前端 未结 30 3198
星月不相逢
星月不相逢 2020-12-13 03:14

I am new to EF core and I\'m trying to get it to work with my ASP.NET Core project.

I get the above error in my startup.cs when trying configure the

30条回答
  •  庸人自扰
    2020-12-13 03:58

    As mentioned by top scoring answer by Win you may need to install Microsoft.EntityFrameworkCore.SqlServer NuGet Package, but please note that this question is using asp.net core mvc. In the latest ASP.NET Core 2.1, MS have included what is called a metapackage called Microsoft.AspNetCore.App

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-2.2

    You can see the reference to it if you right-click the ASP.NET Core MVC project in the solution explorer and select Edit Project File

    You should see this metapackage if ASP.NET core webapps the using statement

    Microsoft.EntityFrameworkCore.SqlServer is included in this metapackage. So in your Startup.cs you may only need to add:

    using Microsoft.EntityFrameworkCore;

提交回复
热议问题