postgresql does not appear in Data Source when generating .ADO.net Entity Data Model

ぃ、小莉子 提交于 2019-11-30 14:19:35

I was confused while 3 days becuase the same problem.

But, I found solve this problem:

  1. install .vsix file in your visual studio environment. https://github.com/npgsql/npgsql/releases/tag/v3.1.8 (NpgsqlDdexProvider)

  2. install Npgsql and EntityFramework6.Npgsql by Nuget Package Manager.

  3. Build your project. (For apply configuration of modified App.xaml by Nuget)

  4. 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.

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.

This issue can been solved by adding a Visual Studio extension provided here: http://www.npgsql.org/doc/ddex.html

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:

  1. Install Npgsql.vsix from the version of npgsql i want to use from here
  2. Remove nuget packages EntityFramework, Npgsql, EntityFramework6.Npgsql
  3. Remove blocks in app.config with any references to these packages including entityFramework and assemblyBindings.
  4. Re-install the nuget packages above in that order
  5. Rebuild

EDIT

I also had to add the following to app.config to successfully run Enable-Migrations

<system.data>
  <DbProviderFactories>
      <remove invariant="Npgsql"/>
      <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF"/>
  </DbProviderFactories>
</system.data>

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:

  1. Create a blank project or use your existing project
  2. Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution
  3. Search for EntityFramework6.NpgSql package (by Shay Rojansky...), currently 3.2.0
  4. Select your new project and click Install

(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:

The ADO.NET provider with invariant name 'Npgsql' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details. at system.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)

In my case, adding this in App.config fixed the problem:

<system.data>
  <DbProviderFactories>
    <remove invariant="Npgsql"/>
    <add invariant="Npgsql" name="Npgsql Data Provider" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF"/>
  </DbProviderFactories>
</system.data>

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:

  • Npgsql.4.0.2
  • EntityFramework.6.2.0 (Microsoft)
  • EntityFramework6.Npgsql.3.2.0
  • System.Threading.Tasks.Extensions.4.5.0
  • System.Runtime.CompilerServices.Unsafe.4.5.0
  • System.ValueTuple.4.5.0

This will also create entries in the app configuration file App.config:

<configSections>
  <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="mssqllocaldb" />
    </parameters>
  </defaultConnectionFactory>

  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
  </providers>
</entityFramework>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!