I have defined a connection string in the appsettings.json file. now I want to read it in my TextDBConext file, how can I do it?
public class TestContext: DbContext
{
public DbSet<TestTable> TestTable { get; set; }
public TestContext()
{
}
public IConfiguration Configuration { get; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Connection string"); //I have hardcoded here, but I want from appsettings.json
}
}
Appsettings.json file:
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"connection_string": "Connection String"
}
}