Bryan
Bryan

Reputation: 5471

EF 7 with ASP.NET 4.51, "No database providers are configured."

I'm getting this error when trying use a EF7 context in a web api 2 (asp.net 4.51) app.

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'm using a traditional web.config

<connectionStrings>
    <add name="MemberContext" connectionString="...." 
         providerName="System.Data.SqlClient">
</connectionStrings>

I'm using ninject to inject the instance of the context.

Upvotes: 0

Views: 133

Answers (1)

tede24
tede24

Reputation: 2354

You need something like this:

public class YourDbContext : DbContext
{

    ...

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer("DefaultConnection");
        base.OnConfiguring(optionsBuilder);
    }
}

Upvotes: 1

Related Questions