I am trying to store my database connection string in a config file so that I can change it depending on the deployment environment. My data access is using EF Core 1.1.0.
I have looked at some full .Net applications that use EF Core and use App.config to store and retrieve the connection string like this:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString);
}
However, when I try that approach in my .Net Core class library project by creating the same App.config file, when I hit the above line of code I get an "Object reference not set to an instance of an object." exception.
So my question is.. Where should these settings be stored in a .Net Core class library project and how are they then retrieved? Should it be App.config, project.json, appsettings.json or some other file??
When i look at this :
Entity Framework Core 1.0 Connection Strings
I think he used Json. Said it was easier, and managed to answer himself. Make sure your files see each other and it should be ok. Sorry if it didn't help.