Integrating Entity Framework 6.0 with Postgres 9.3

entity-framework-6 postgresql ssms-2014 visual-studio-2013


I have a local database developed in Postgres 9.3. The Postgres server name on my computer is just "localhost". I would like to use the Entity Framework 6 Designer that is built into Visual Studio 13 to automatically generate a data model of EF classes and properties that correspond to the database tables and columns.

As described in various web articles, and using Nuget package manager, I added onto VS 13 these extensions or packages: EF 6, Npgsql, Npgsql Data Provider for EF 6, and Dotconnect express for Postgresql. Afterwards, in the VS 13 Server Explorer window, I was able to connect and see my Postgres tables and columns.

However, I cannot seem to get the EF Designer Wizard to automatically generate the .edmx file. I tried adding an data object, selecting "EF Designer from Database" and alternatively, "Code First from Database." When I got to the next screen, I had to choose a Data Source. I tried both "MS SQL Server Database File" and alternatively, "Other." For the Data Provider, there was no other option than ".Net Data Provider for SQL."

In the next screen I tried to create a connection, using SQL server authentication, with user name and password, but I could never get VS 13 to connect or even display the Postgres server like it did in Server Explorer window. For the Server Name I used the same one as I used for the Server Explorer window, ie. localhost.mydatabasename.myschema. For the SQL User, I used the owner of the Postgres database, a Role I created, ie. mydatabasename_role.

When that faied, I tried going into MS SQL Management Studio 2014 to see if I could display the Postgres server there, using the same info used in the Server Explorer window, but I could not get SSMS to display the Postgres server there either. Is there a way to automatically generate the data model and .edmx file as I have been trying, using just VS 13 and SSMS 14? Or do I need to purchase the proprietary / licensed version of dotconnect for Postgres developed by Devart? Thank you in advance.

5/30/2014 6:21:17 AM

Accepted Answer

A Visual Studio plugin is currently being developed which supports the EF Designer Wizard. You can find it here:

6/19/2014 10:03:19 PM

Popular Answer

After about a week of research and banging my head againts my desk, I FINALLY got my Npgsql MVC Entity Framework application to work... and work WITH the wizard. The steps are below....

1) Close Visual Studio, then download and install Npgsql PostgreSQL Integration from:

2) Reboot your computer. (yes, it's needed, I promise)

3) Open visual studio and install the following NuGet packages, IN THE ORDER listed and the VERSION listed...

--> EntityFramework version 6.0.0, then clean and rebuild

--> Npgsql 3.1.0, then clean and rebuild

--> EntityFramework6.Npgsql 3.1.1, then clean and rebuild

NOTE: You may need to uninstall other Nuget packages if these will not install in the order and version listed. If so, just make note and add them back later. and yes, you will want to clean/rebuild between each one above.

4) Close all applications and restart your computer. (yes, it's needed, I promise)

5) After your computer restarts, open Visual Studio again and go to your solution. NOTE: I advise you add a new project for your database connection, but this is more a preference than anything.

6) Try using the Entity Framework Wizard again. You should see the Npgsql selections and it shouldn't just crash on you.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow