I seem to be getting this error message when using Entity Framework 7 and MVC6
System.InvalidOperationException No database providers are configured. Configure a database provider by overriding OnConfiguring in your DbContext class or in the AddDbContext method when setting up services.
I believe i have done everything i am supposed to be doing, so maybe its a bug. I am using version 7.0.0-beta7 of Entity Framework.
I have setup my DbContext, an interface so i can mock DbContext (was needed in EntityFramework 6 for unit testing). My services take the interface as a constructor and i have setup DI in MVC 6.
In my Startup.cs file i have the following
public void ConfigureServices(IServiceCollection services)
{
// entity framework
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<MyDbContext>(options =>
options.UseSqlServer(Configuration["Data:MyConnection:ConnectionString"])
);
// Add MVC services to the services container.
services.AddMvc();
// new context on each request
services.AddScoped<IMyDbContext, MyDbContext>();
}
I have checked my connectionString and that is returning a valid connection. I have also checked in my service that the object is being injected, and it is not null, so that should all work.
My config.json file looks like this
{
"Data": {
"MyConnection": {
"ConnectionString": "Server=(local);Database=XXXX;Trusted_Connection=True;"
}
}
}
My DbContext does not override the OnConfiguring method, because i believe it is not needed as i am doing it all as above? Am i right? What am i missing? Looked at lots of different websites, i guess some are using old code, because some methods dont exist and other websites have the same as what i have.
MyDbContext
in code?