AddDbContext was called with configuration, but the context type 'MyContext' only declares a parameterless constructor?

后端 未结 1 532
一生所求
一生所求 2020-12-29 01:29

In the following console application (.Net core 2.0), the scaffold-dbcontext created the following DbContext

public partial class M         


        
相关标签:
1条回答
  • 2020-12-29 01:44

    As the error said it if you configure your MyContext through AddDbContext then you need too add a constructor that receive a parameter of type DbContextOptions<MyContext> into your MyContext class like below

    public MyContext(DbContextOptions<MyContext> options)
        : base(options)
    { }
    

    If you don't do that, ASP.Net Core will not be able to inject the configuration you set with AddDbContext.

    0 讨论(0)
提交回复
热议问题