The ASP.NET core example will throw an exception in ASP.NET Core 2.1 with EF Core 2.1. Which will throw the System.InvalidOperationException.
With the message:
'No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.'
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
It looks like I was just missing the constructor within a controller.
If you are going to migrate the default generated connection string don't forget to add to each controller
public class SomeController : Controller
{
// This is needed
private readonly YourContext _context;
public SomeController(YourContext context)
{
_context = context;
}
// Routing and Controller logic...
}
Why isn't this code included in the example if it is needed?
Most helpful comment
It looks like I was just missing the constructor within a controller.
If you are going to migrate the default generated connection string don't forget to add to each controller