33

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

6
  • Are you missing a using statement or an assembly reference? Did you read the error? Commented Mar 5, 2018 at 18:27
  • Like this? stackoverflow.com/questions/45068696/… Commented Mar 5, 2018 at 18:28
  • Yes I have checked about that. I have added all the necessary using statements. Is there any other which I missed? Commented Mar 5, 2018 at 18:28
  • @DavidG Yes I have checked that answer and added those using but still the same error. Commented Mar 5, 2018 at 18:29
  • 2
    And do you have a reference to the Npgsql.EntityFrameworkCore.PostgreSQL Nuget package? Commented Mar 5, 2018 at 18:30

3 Answers 3

73

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;
    
Sign up to request clarification or add additional context in comments.

4 Comments

I have done both of these things but still having the same issue... I'm guessing it has to do with using version 5.X of these? EDIT: Solved by saving changes to NuGet packages (you can do this by restarting visual studio)
For those of you who are too quick to look: this is the Npgsql.EntityFrameworkCore nuget package, not the Microsoft.EntityFrameworkCore package that you need to add...
Thanks Andreas, I solve the problem when I install the Npgsql.EntityFrameworkCore but i didn't even import it into the code. weird.
Even after doing the above 2 steps I still had the same build error in Rider IDE. A simple IDE restart fixed the issue!
11

I solved this problem by checking that all these 3 packages are intalled:

Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore   
Npgsql.EntityFrameworkCore.PostgreSQL

and the third one was the problem for my application. It was not installed. Don't forget to add reference for any of these packages when needed in your code.

Comments

0

I had to install the following package: NuGet\Install-Package Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime -Version 8.0.0-preview.4

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.