How to fix ‘No database providers are configured’ when scaffolding a controller in ASP.NET 5

If got this error when trying to scaffold a new controller (MVC and Web Api) for an ASP.NET 5 web app using Visual Studio 2015.

There was an error running the selected code generator:
'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.'

Scaffolding

MemeberContext was not part of the web application project, instead it was in a referenced class library. This was causing the problem.

To resolve it go to the Startup.cs file.

Inside the ConfigureServices(..) method add something like –

            services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext<MemberContext>(options =>
                options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

Of course you need to make sure your Data:DefaultConnection:ConnectionString is pointing to the right place.