Entityframework.docs: ASP.NET Core Example does not work.

Created on 22 Jun 2018  Â·  2Comments  Â·  Source: dotnet/EntityFramework.Docs

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.'


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

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

public class SomeController : Controller
{
   // This is needed
    private readonly YourContext _context;

    public SomeController(YourContext context)
    {
         _context = context;
     }
    // Routing and Controller logic...
}

All 2 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SychevIgor picture SychevIgor  Â·  4Comments

weitzhandler picture weitzhandler  Â·  4Comments

MohammadMQ picture MohammadMQ  Â·  3Comments

divega picture divega  Â·  3Comments

Praveen-Rai picture Praveen-Rai  Â·  4Comments