Cannot solve this error, "No database provider has been configured for this DbContext"

asp.net-core asp.net-core-2.1 c# entity-framework entity-framework-core

Accepted Answer

Add ConnectionService.Set to Startup.cs

public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
        ConnectionService.Set(configuration);
    }

ConnectionService.cs

public static string connstring = "";
public static string Set(IConfiguration config)
    {
        connstring = config.GetConnectionString("MyConnection");
    }

ConfigurationContext.cs

public class ConfigurationContext : DbContext {

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
        optionsBuilder.UseSqlServer(ConnectionService.connstring);
    }

}
0
1/22/2020 2:19:48 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow