i have the following error message:
Unable to create a 'DbContext' of type ''. The exception '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.
I get this when I try to add my first migration. How can I fix that?
This is my context class:
public partial class MyContext : DbContext { public MyContext(DbContextOptions options) : base(options) { } public virtual DbSet Users { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { OnModelCreatingPartial(modelBuilder); } partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } And this is my Program.cs:
var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllersWithViews(); builder.Services.AddRazorPages(); builder.Services.AddDbContext(options => options .UseMySql( builder.Configuration.GetConnectionString("MyContext"), new MariaDbServerVersion("10.5.18-MariaDB") ) ); builder.Services.AddTransient(); var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseMigrationsEndPoint(); app.UseWebAssemblyDebugging(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseBlazorFrameworkFiles(); app.UseStaticFiles(); app.UseRouting(); app.MapRazorPages(); app.MapControllers(); app.MapFallbackToFile("index.html"); app.Run(); I hope someone can help me
Источник: https://stackoverflow.com/questions/757 ... -dbcontext
Мобильная версия