I try to use DbContext from another class but I got exception down below.
"System.InvalidOperationException: 'No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext"
I added ref project in my api app already.
Program.cs
using DAL.ModelContext;
using Microsoft.EntityFrameworkCore;
builder.Services.AddDbContext<MyDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("MyDbServer")));
MyDbContext.cs --> I deleted the code.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
}
Thx for your reply.