Using npgsql 12 and ef 6 together - have anyone succeeded with it?

c# entity-framework npgsql postgresql

Question

I'm trying to create a small POC for my boss about the hybrid of npgsql 12 and ef6, created a new project on visual studio created a sample database created the corresponding classes and the dbcontext yet, whenever I try and use ef to access the database I receive the folowing error:

The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

I know that it should be supported for quite some time now http://fxjr.blogspot.co.il/2013/06/initial-ef-6-support-added-to-npgsql.html

however I can't seem to get it to work, my App.Config file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://    go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework"     type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,     Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"     requirePermission="false" />
    <!--<section name="entityFramework" type="Npgsql.NpgsqlFactory, Npgsql,     Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />-->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient"     type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlFactory, Npgsql" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <add name="Npgsql Data Provider"
            invariant="Npgsql"
            description="Data Provider for PostgreSQL"
            type="Npgsql.NpgsqlFactory, Npgsql" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="CoolestPGSoft"
          connectionString="Server=127.0.0.1;Port=5432;Database=CoolestPGSoft;User Id=postgres;Password=********;"
          providerName="Npgsql" />
  </connectionStrings>
</configuration>

any help would be appreciated!

1
6
11/25/2013 11:11:24 PM

Accepted Answer

Now it only works with last beta version of Npgsql http://pgfoundry.org/frs/download.php/3494/Npgsql2.0.13.91-bin-ms.net4.5Ef6.zip And you must change

  <provider invariantName="Npgsql" type="Npgsql.NpgsqlFactory, Npgsql" /> 

to

 <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql" />
3
11/27/2013 3:36:13 PM

Popular Answer

I got it EF6 and Npgsql to work following:

Entity Framework 6 with Npgsql

PMC> Install-Package EntityFramework
(should give you version 6)

PMC> Install-Package Npgsql.EF6 -Pre
(should give you 2.0.12-pre4)

And these go into App.config

  <system.data>
    <DbProviderFactories>
      <add name="Npgsql Data Provider" 
           invariant="Npgsql" 
           description ="Data Provider for PostgreSQL" 
           type="Npgsql.NpgsqlFactory, Npgsql" />
    </DbProviderFactories>
  </system.data>

  <connectionStrings>
    <add name="PostgreSQL" 
         providerName="Npgsql" 
         connectionString="Server=asdf;Port=5432;User Id=asdf;Password=asdf;Database=asdf;enlist=true" />
  </connectionStrings>

  <entityFramework>
    <providers>
      <provider invariantName="Npgsql" 
                type="Npgsql.NpgsqlServices, Npgsql" />
    </providers>
  </entityFramework>


Related Questions





Related

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