简体   繁体   中英

Npgsql Entityframework - Can't see Postgres provider for ADO.net Entity Data Model

I'm trying to hook up a Postgres database to a EDMX designer.

I've installed the EntityFrameowrk6.npgsql nugget module as described here: http://www.npgsql.org/ef6/index.html (The database already has he uuid-ossp extension)

I've then installed the extension package, as described here: http://www.npgsql.org/doc/ddex.html

Finally I've updated the npgsql module to v3.2.1 to match the extension version as suggested in the integration documentation.

I can connect to my database using visual studio's server browser.

After doing this, I've gone to add a ado.net entity data model to my project, but he only providers available to me are the Microsoft sql ones. No Postgres in sight!

I'm running Visual Studio Community 2017, which is fully up to date, and the only other extension installed is AnkhSVN. It's a C# project currently configured for .net 4.5.1 (but I'm more than happy and willing to change the target framework to get things working!)

The only Nuget packages in my project are the ones described above and their dependencies.

Much googling has result in just various tutorials telling me to do basically the above, or people adding elements to app.config (which I've tried and failed with, and reverted) that the npgsql documentation explicitly states you shouldn't need to do.

Any help much appreciated!

Edit: This is my App.Config as it currently stands.

<?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.1" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.2.1.0" newVersion="3.2.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Turns out the issue I had was that I wasn't rebuilding my project/solution after adding the NuGet stuff. Mostly due to the fact I was replacing an old SQL EF implementation with the Postgre one, and couldn't build due to the myriad of missing references.

The question here suggested that rebuilding was something that should happen: Entity Framework 6.1.1 and Npgsql 2.2.3: Compatible Entity Framework database provider could not be found

So, I commented out most of my code, rebuilt, and the provider has turned up where I'm expecting it.

It is crashing Visual Studio (boo hiss!), but that's a separate issue.

I hope this is of help to some poor soul.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM