Search code examples
c#entity-frameworkasp.net-core-mvcasp.net-core-2.0

'DbContextOptionsBuilder' does not contain a definition for UseNpgsql()


I am facing an issue while giving the connectionstring to get it connect to PostgreSQL through the AddDbContext() method in ConfigureServices method of Startup.cs

I'm getting this error while calling the function options.UseNpgsql() (see the image below).

I have seen other questions regarding this but those are for usesqlserver() and also they did not solve my problem.

enter image description here


Solution

  • Two things to check:

    1. Are you missing a reference to the Npgsql.EntityFrameworkCore.PostgreSQL Nuget package?
    2. Are you missing the correct import. The UseNpgsql() extension method is in the Microsoft.EntityFrameworkCore namespace which means you should have this line:

      using Microsoft.EntityFrameworkCore;