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

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

    Easy way to fix this issue

    Error message:

    Solution:
    to install "microsoft.entityframeworkcore.sqlserver" with NuGet

    Fixed :

    PS: make sure you have using EF on the content "using Microsoft.EntityFrameworkCore;"

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

    Project is works in DotNET Core 3.1+ or higher(future)

    Add this package:

    1. NuGet: Microsoft.EntityFrameworkCore.Tools
    2. Project Config (.csproj): <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8">
    0 讨论(0)
  • 2020-12-13 03:45

    Wow so many answers yet none mentioned this Microsoft.EntityFrameworkCore.InMemory package!

    Add the reference to this package: <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.2" /> and you should be good to go.

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

    For asp.net core version 2.1 make sure to add the following package to fix the problem. (At least this fix the issue using SQLite)

    dotnet add package Microsoft.EntityFrameworkCore.Sqlite
    dotnet add package Microsoft.EntityFrameworkCore.Design
    

    Here is the reference of the documentation using SQLite with entity framework core. https://docs.microsoft.com/en-us/ef/core/get-started/netcore/new-db-sqlite

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

    Currently working with Entity Framework Core 3.1.3. None of the above solutions fixed my issue.

    However, installing the package Microsoft.EntityFrameworkCore.Proxies on my project fixed the issue. Now I can access the UseLazyLoadingProxies() method call when setting my DBContext options.

    Hope this helps someone. See the following article:

    Lazy Loading in EF Core

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

    your solution works great.

    When I saw this video till 17 Minute: https://www.youtube.com/watch?v=fom80TujpYQ I was facing a problem here:

     services.AddDbContext<PaymentDetailContext>(options =>
        options.UseSqlServer(Configuration.GetConnectionString("DevConnection")));
    

    UseSqlServer not recognizes so I did this Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.5

    & using Microsoft.EntityFrameworkCore;

    Then my problem is solved. About me: basically I am a purely PHP programmer since beginning and today only I started .net coding, thanks for good community in .net

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