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

前端 未结 30 3159
星月不相逢
星月不相逢 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:50

    I had same issue but problem went off after going back and fixing DbContext incorrect syntax issue such as it should have been ExampleDbContextClass: DbContext whereas I had missed DbContext part in Context Class where you define your DbSet. Also, I verified following dependencies are needed in order to achieve connection to SqlServer. <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.6" /> Also verify that Version you install is less than your project's current version to be on safe side. Such as if your project is using 3.1 do not try to use newer one which would be for example 3.1.9. I had issue with that too.

    0 讨论(0)
  • 2020-12-13 03:51

    Install package, EntityFrameworkCore.SqlServer:

    PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.3
    

    Nuget: https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer/

    0 讨论(0)
  • 2020-12-13 03:51

    I also had the same problem. I added the following. It works for me

    Microsoft.EntityFrameworkCore.SqlServer
    
    0 讨论(0)
  • 2020-12-13 03:53

    For anyone still having this problem: Use NuGet to install: Microsoft.EntityFrameworkCore.Proxies

    This problem is related to the use of Castle Proxy with EFCore.

    0 讨论(0)
  • 2020-12-13 03:54

    The Package is missing. Open Package Manager Console and execute the code below:

    Install-Package Microsoft.EntityFrameworkCore.SqlServer 
    
    0 讨论(0)
  • 2020-12-13 03:54

    I got around this by simply:

    Add SqlServerDbContextOptionsExtensions to the class in question Resolve SqlServerDbContextOptionsExtensions

    This fixes the issue, must be missing some reference by default.

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