Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UseNpgsql not available in IServiceCollection in .NET Core

Tags:

c#

postgresql

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?

like image 460
Jonathan Burgos Gio Avatar asked Jul 12 '17 22:07

Jonathan Burgos Gio


1 Answers

I had the same issue. I resolved it by adding

using Microsoft.EntityFrameworkCore;
like image 142
user2612935 Avatar answered Oct 23 '22 21:10

user2612935