Jonathan Burgos G.
Jonathan Burgos G.

Reputation: 344

UseNpgsql not available in IServiceCollection in .NET Core

I have .NET Core project in Visual Studio 2017. I am trying to add (Postgresql) database connection. Here is a code:

public void ConfigureServices(IServiceCollection services)
{
     services.AddMvc();

     services.AddDbContext<ConexionWebApi>(options => {
     options.UseNpgsql("ConnectionString", b => b.MigrationsAssembly("WebAPISample"));
     });

}

But useNpgsql generates the following error:

'DbContextOptionsBuilder' does not contain a definition for 'UseNpgsql' and no extension method 'UseNpgsl' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly refence?)

I installed the followings NuGet packages:

Microsoft.EntityFrameworkCore.Tools,    
Npgsql.EntityFrameworkCore.PostgreSQL,  
Npgsql.EntityFrameworkCore.PostgreSQL.Design.

Should I install some other library?

Upvotes: 8

Views: 6238

Answers (1)

RJ Vega
RJ Vega

Reputation: 98

I had the same issue. I resolved it by adding

using Microsoft.EntityFrameworkCore;

Upvotes: 6

Related Questions