'Unable to create an object of type 'AppDbContext'. asp.net 6/mvc
MY ERROR: ı want to "add-migration" but ı cannot also ı use web app and .NET 6.0
Unable to create an object of type 'AppDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
this is my codes,please help me
--my program.cs--
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Configuration.GetConnectionString("DefaultConnectionString");
builder.Services.AddRazorPages();
--my AppDbContext.cs--
public class AppDbContext:DbContext
{
public AppDbContext(DbContextOptions<AppDbContext>options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Actor_Movie>().HasKey(ActM => new
{
ActM.ActorId,
ActM.MovieId
});
modelBuilder.Entity<Actor_Movie>().HasOne(m => m.Movies).WithMany(ActM => ActM.Actors_Movies).HasForeignKey(m => m.MovieId);
modelBuilder.Entity<Actor_Movie>().HasOne(m => m.Actors).WithMany(ActM => ActM.Actors_Movies).HasForeignKey(m => m.ActorId);
base.OnModelCreating(modelBuilder);
}
public DbSet<Actors> Actors { get; set; }
public DbSet<Movies> Movies { get; set; }
public DbSet<Actor_Movie> Actors_Movies { get; set; }
public DbSet<Producers> Producers { get; set; }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|