The error which I am facing –
PM> update-database
Build started…
Build succeeded.
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Failed to load configuration from file ‘C:UsersshubhsourcereposProjectOneappsettings.json’.
Unable to create a ‘DbContext’ of type ”. The exception ‘Unable to resolve service for type ‘Microsoft.EntityFrameworkCore.DbContextOptions`1[ProjectOne.Data.ApplicationContext]’ while attempting to activate ‘ProjectOne.Data.ApplicationContext’.’ was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
PM>
ApplicationContext.cs –
using Microsoft.EntityFrameworkCore;
using ProjectOne.Models;
namespace ProjectOne.Data
{
public class ApplicationContext : DbContext
{
public ApplicationContext(DbContextOptions<ApplicationContext> options):base(options) { }
public DbSet<Employee> Employees { get; set; }
public DbSet<Department> Departments { get; set; }
}
}
appsettings.json –
{
{
"ConnectionStrings": {
"ProductionDB": "Data Source=DESKTOP-R6LR1KA\SQLEXPRESS;Initial Catalog=MultiTable;Integrated Security=True;Trust Server Certificate=True"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Program.cs –
using Microsoft.EntityFrameworkCore;
using ProjectOne.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<ApplicationContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("ProductionDB")));
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
I have installed Entity FrameWork Tools, CORE, Design as well.
Its not working still hope u fix it up .. I am using 8.0.7 latest ones