project version : .netcore2.2
I m working With N-Tier Architecture in .netcore2.2
when I defining below configuration then give the error:
DbContextOptionsBuilder' does not contain a definition for 'usesqlserver' and no extension method '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
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?
UseSqlServer()
. – Xueli Chen