I succeeded in accessing an existing postgresql dbase by using npgsql directly. I used for this:
- PostgreSQL 9.0.10 (32 bit)
- Visual Studio 2015 Community (64 bit)
- NpgSql 2.2.5 (through Manage Nuget Packages)
The dbase however has 25+ tables and 400+ columns and such my intention is to to use entity framework + .ADO.net Entity Data Model to avoid having to code access to all columns. I searched and tried everything on this site, npgsql site http://www.npgsql.org/doc/ddex.html, ... but I I did not succeeded in generating an .ADO.net Entity Data Model because postgresql does not appear in Data Source.
I used for this:
- PostgreSQL 9.0.10 (32 bit)
- Visual Studio 2015 Community (64 bit)
- NpgSql 2.2.5 (through Manage Nuget Packages)
- Setup_Npgsql-2.2.5.0-r3-net45.exe (from GitHub because some sites indicated the requirement of having the same version into GAC as the used package in visual studio project; I did not took version 3.0.0 as Github misses install files).
- Npgsql.entityframework6 2.2.5 (through Manage Nuget Packages)
- Entityframework 6.1.3 (through Manage Nuget Packages)
What do I have to do so postgresql appears as Data Source when trying to generate an .ADO.net Entity Data Model?
Or does Visual Studio 2015 community does not allows the generation of .ADO net entity data model for postgresql ?
EDIT I have added the following info in the hope for a reply:
Microsoft Windows 8.1 6.3.9600 build 9600 64-bit used
Extract out "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config"
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
Extract out "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config"
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
"Visual Studio - packages.config"
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="Npgsql" version="2.2.5" targetFramework="net452" />
<package id="Npgsql.EntityFramework" version="2.2.5" targetFramework="net452" />
</packages>
"Visual Studio - App.config"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
This bugged me for hours in VS2017. I played with the
app.config
settings manually with no joy. The steps to fix it for me were:Npgsql.vsix
from the version of npgsql i want to use from hereEntityFramework
,Npgsql
,EntityFramework6.Npgsql
app.config
with any references to these packages includingentityFramework
andassemblyBindings
.EDIT
I also had to add the following to
app.config
to successfully runEnable-Migrations
In VS 2019
Install the 'PostgreSQL provider for Entity Framework 6' package using NuGet. You do not need to install anything else, Npgsql is included in the package.
Notes:
The package works for the current project only and must be reinstalled with a new project, nothing is installed machine-wide.
Don't mix installing the provider package for your application (the problem to fix here) and installing an extension to Visual Studio referred as 'Visual Studio Integration' (Npgsql.vsix) so that VS can open PostgreSQL databases (e.g. in Server Browser).
To install PostgreSQL provider for EF6:
(You can use the PM command and type
Install-Package EntityFramework6.Npgsql -Version 3.2.0
if you prefer)In case of Factory not found exception
For some reason you may receive an exception when executing your application because .NET can't find the provider factory:
In my case, adding this in
App.config
fixed the problem:If someone can explain why the section above is missing...
Now you should be able to generate a derived DbContext for PostgreSQL with ADO.NET Entity Data Model wizard.
Details of the installation, for information only
This will copy files into a subdirectory
package
of your project and reference them:This will also create entries in the app configuration file
App.config
:I had been the same issue for a while. Then, I've tried to install dotconnect https://www.nuget.org/packages/dotConnect.Express.for.PostgreSQL/7.4.506/. And, it works! hope this help.
I was confused while 3 days becuase the same problem.
But, I found solve this problem:
install .vsix file in your visual studio environment. https://github.com/npgsql/npgsql/releases/tag/v3.1.8 (NpgsqlDdexProvider)
install Npgsql and EntityFramework6.Npgsql by Nuget Package Manager.
Build your project. (For apply configuration of modified App.xaml by Nuget)
You can use ADO.NET Entity Model Generation.
Also, dotConnect not support Entity Model in Express version. It supported in only commercial version.
But currently, Npgsql has immediately close bug in EDM. so, I finding solution.
This issue can been solved by adding a Visual Studio extension provided here: http://www.npgsql.org/doc/ddex.html