[英]DbContextOptionsBuilder' does not contain a definition for 'usesqlserver' and no extension method 'usesqlserver' in asp.net core 2.2?
project version : .netcore2.2项目版本:.netcore2.2
I m working With N-Tier Architecture in .netcore2.2我正在 .netcore2.2 中使用 N 层架构
when I defining below configuration then give the error:当我定义下面的配置然后给出错误:
DbContextOptionsBuilder' does not contain a definition for 'usesqlserver' and no extension method 'usesqlserver' 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**
}
}
startup.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!");
});
}
}
program.cs程序.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>();
}
}
see below image:见下图:
when I install this:当我安装这个时:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 2.2.6
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 3.1.2
Current Error:当前错误:
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).
I m trying to solve this error last midday but error not solved我试图在上中午解决这个错误,但错误没有解决
plz, help? lz,有帮助吗?
安装nuget包
Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install the nuget package:安装 nuget 包:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
And put this directive in your class:并将此指令放在您的班级中:
using Microsoft.EntityFrameworkCore;
Without the directive or the nuget package it doesn't work如果没有指令或 nuget 包,它就不起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.