Having the same problem as the name mentioned, but without any problem with the key or connection, I finally found a solution to this problem. In particular, using forest controllers / representations from model classes created using a database-based approach. In your DbContext class, you MUST HAVE a class constructor that accepts the DbContextOptions<MyDb> parameter, which for some reason is not added using the "Scaffold-DbContext" command in the package manager console (with an ASPNETCORE project)
public partial class MyDbContext : DbContext { public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { } public virtual DbSet<MyModel> MyModel { get; set; } }
For others, there should also be a connection string in the appsettings.json file and the following code in the ConfigureServies method of the startup.cs add file:
services.AddDbContext<MyDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("MyDbContection")));
source share