I have a .Net Core WebApplication Project in which the Context Class is in a Class Library. If I hard code the connection string in the OnConfiguring(DbContextOptionsBuilder
I was having the same issue when I when providing options along with dbcontext while adding dbcontext to services like:-
services.AddDbContext(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
then I added dbcontext without options like below and it fixed the problem for me
services.AddDbContext();
also I had to add OnConfiguring method to dbcontext class so the context can access the connection string:-
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=IdenDB;Trusted_Connection=True;MultipleActiveResultSets=true");
}
I am not sure if this is the right way of doing things since I just started with core but here is an answer which explains this issue in a bit more detail