DbContextOptionsBuilder'不包含'usesqlserver'的定义并且在asp.net core 2.2中没有扩展方法'usesqlserver'?

Rah*_*til 4 asp.net-core

项目版本:.netcore2.2

我正在 .netcore2.2 中使用 N 层架构

当我定义以下配置时给出错误:

DbContextOptionsBuilder”不包含“usesqlserver”的定义,并且没有扩展方法“usesqlserver”


    public class CustomerDataAccess : DbContext, ICustomerDataAccess
    {

        protected override void OnConfiguring(DbContextOptionsBuilder dbContextOptionsBuilder)
        {
            if (!dbContextOptionsBuilder.IsConfigured && _configuration.GetConnectionString("DMEBaseConnection") != null)
            {
                dbContextOptionsBuilder.UseSqlServer(_configuration.GetConnectionString("connectionstringname")); **//here give an error**
            }
        }
Run Code Online (Sandbox Code Playgroud)

启动.cs

    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
    }
Run Code Online (Sandbox Code Playgroud)

程序.cs

namespace projectname
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }
}
Run Code Online (Sandbox Code Playgroud)

见下图:

在此输入图像描述

当我安装这个时:

Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 2.2.6
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.2
Run Code Online (Sandbox Code Playgroud)

当前错误:

NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.2.0 requires Microsoft.EntityFrameworkCore.SqlServer (>= 2.2.0 && < 2.3.0) but version Microsoft.EntityFrameworkCore.SqlServer 3.1.2 was resolved.

projectname-> projectname.BusinessLogic -> projectname.DataAccess -> Microsoft.EntityFrameworkCore (>= 3.1.2) 
 projectname-> Microsoft.AspNetCore.App 2.2.0 -> Microsoft.EntityFrameworkCore (>= 2.2.0 && < 2.3.0).

Run Code Online (Sandbox Code Playgroud)

我昨天中午试图解决这个错误,但错误没有解决

请问,帮忙吗?

Fra*_*edu 5

安装nuget包

Install-Package Microsoft.EntityFrameworkCore.SqlServer
Run Code Online (Sandbox Code Playgroud)