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

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

    I had this trouble when I moved to Microsoft.EntityFrameworkCore.SqlServer v3.0.0 and Microsoft.EntityFrameworkCore.Tools v3.0.0

    When I changed back to v2.2.6 on both libraries, the error went away. This is more of a workaround than a solution but it'll get you up and running till the issue is fixed.

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

    I had to use the line

     services.AddEntityFrameworkSqlite().AddDbContext<MovieContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MovieContext")));
    

    in the ConfigureServices method in the Startup.cs

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

    Project -> ManageNugetPackages -> Browse -> Search "Microsoft.EntityFrameworkCore.SqlServer" and install or update.

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

    I believe this can be solved by adding a project reference to Microsoft.EntityFrameworkCore.SqlServer.Design

    Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design
    

    Microsoft.EntityFrameworkCore.SqlServer wasn't directly installed in my project, but the .Design package will install it anyway as a prerequisite.

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

    If you are facing this issue in case of Sqlite then

    . I think this is the problem with version of Sqlite,I had the same problem when I was using this versions of SqLite

    Version 2.2.4:

    After checking version here I changed the version then it worked.

    No error after using this

    Version 2.1.2:

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

    I was using Visual Studio Code.

    1) Try to install the package 'Microsoft.EntityFrameworkCore.SqlServer' by specifying the version number.

    VS Code:

    'dotnet add package Microsoft.EntityFrameworkCore.SqlServer -v 1.1.1'

    Visual Studio:-

    'Install-Package Microsoft.EntityFrameworkCore.SqlServer -v 1.1.1'

    Refer the link 'Package 'Microsoft.EntityFrameworkCore.SqlServer' is incompatible with 'all' frameworks in the project' for doing it.

    2) Then add the namespace 'using Microsoft.EntityFrameworkCore;' manually in the Startup.cs file.

    Refer the below link https://github.com/aspnet/EntityFramework/issues/7891.

    3) If you get any dependency issue for 'Microsoft.EntityFrameworkCore.SqlServer.Design', like "Package 'Microsoft.EntityFrameworkCore.Design' is incompatible with 'all' frameworks in project" ,we need to run the below command,

    VS Code:-

    dotnet add package Microsoft.EntityFrameworkCore.Design -v 1.1

    Visual Studio

    Install-Package Microsoft.EntityFrameworkCore.Design -v 1.1

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