Unable to create an object of type 'MyContext'. For the different patterns supported at design time

前端 未结 9 2991
逝去的感伤
逝去的感伤 2021-02-19 16:42

I have ConsoleApplication on .NET Core and also i added my DbContext to dependencies, but howewer i have an error:

Unable to create an object of type \'My

9条回答
  •  花落未央
    2021-02-19 17:18

    I resolve this issue by this way:

        public DbSet Posts { get; set; }
        public DbSet Votes { get; set; }
    
        public MyContext(DbContextOptions options) : base(options) { Database.EnsureCreated(); }
    
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfigurationsFromAssembly(typeof(MyContext).Assembly);
        }
    

提交回复
热议问题