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

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

    Install below NuGet Package will solve your issue

    Microsoft.EntityFrameworkCore.SqlServer

    Install-Package Microsoft.EntityFrameworkCore.SqlServer

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

    In Visual Studio, check the NuGet Package Manager => Manage Packages for Solution, check all this packages, whether got installed in your solution or not, as below:

    1. EntityFrameworkCore
    2. Microsoft.EntityFrameworkCore
    3. Microsoft.EntityFrameworkCore.InMemory
    4. Microsoft.EntityFrameworkCore.Relational
    5. Microsoft.EntityFrameworkCore.Sqlite.Core
    6. Microsoft.EntityFrameworkCore.SqlServer
    7. Microsoft.EntityFrameworkCore.Tools

    I solved the same issues after check all the above packages have been installed.

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

    Follow the steps below.

    Install Entity Framework Core Design and SQL Server database provider for Entity Framework Core:

    dotnet add package Microsoft.EntityFrameworkCore.Design
    dotnet add package Microsoft.EntityFrameworkCore.SqlServer
    

    Import Entity Framework Core:

    using Microsoft.EntityFrameworkCore;
    

    And configure your DbContext:

    var connectionString = Configuration.GetConnectionString("myDb");
    services.AddDbContext<MyDbContext>(options => 
        options.UseSqlServer(connectionString)
    );
    
    0 讨论(0)
  • 2020-12-13 03:32

    first add Install-Package Microsoft.EntityFrameworkCore.SqlServer

    next add in your .cs file using Microsoft.EntityFrameworkCore;

    finally add this in your core Startup.cs

      public void ConfigureServices(IServiceCollection services)
            {
                services.AddEntityFrameworkSqlServer().AddDbContext<ApplicationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MovieContext")));
            }
    
    0 讨论(0)
  • 2020-12-13 03:33

    Install-Package:

    **Microsoft.EntityFrameworkCore.SqlServer**
    

    then add the top of your class:

    **Microsoft.EntityFrameworkCore;**
    

    that's worked for me

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

    This is a known issue in the project system. See dotnet/project-system#1741

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