i am having error when i tries to scaffold a controller "No database provide rhas been configured for this dbcontext. a provider can be configured by overriding the db context.On Configuring method or by using Adddbcontext on the applocation service provider.if adddbcontext is used, then also ensure that your dbcontext type accpets a dbcontextoptions<TContext? object in its constructor and passes it to the base constructor for DbContext".
Here is what i haved done so far
startup.cs
public void ConfigureServices(IServiceCollection services) { services.AddDbContext<IntranetContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DevConnection"))); services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores<ApplicationDbContext>(); services.AddControllersWithViews(); services.AddRazorPages(); }
appsettings.json
{"Logging": {"LogLevel": {"Default": "Information","Microsoft": "Warning","Microsoft.Hosting.Lifetime": "Information" } },"AllowedHosts": "*","ConnectionString": {"DevConnection": "Server= mypc;Database:ERP;Trusted_Connection=True;MultipleActiveResultSets=true" } }
context file
using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Intranet { public class IntranetContext : DbContext { //public IntranetContext(DbContextOptions<IntranetContext> options) : base(options) //{ //} public IntranetContext() // C# will call base class parameterless constructor by default { } public DbSet<GenerateDocumentNumber> GenerateDocumentNumber { get; set; } } }