2013-11-25 7 views
6

Sto cercando di creare un piccolo POC per il mio capo circa l'ibrido di npgsql 12 e EF6, creato un nuovo progetto sul Visual Studio creato un database di esempio creato le classi corrispondenti e il DbContext eppure, ogni volta che provo e utilizzare ef per accedere al database che ricevo l'errore folowing:Utilizzo di npgsql 12 e ef 6 insieme: qualcuno ci è riuscito?

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.

so che dovrebbe essere sostenuto per un bel po 'di tempo http://fxjr.blogspot.co.il/2013/06/initial-ef-6-support-added-to-npgsql.html

però io non riesco a farlo funzionare, mia App.C il file onfig è simile al seguente:

<?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> 

qualsiasi aiuto sarebbe apprezzato!

risposta

3

Ora funziona solo con la versione ultima beta di Npgsql http://pgfoundry.org/frs/download.php/3494/Npgsql2.0.13.91-bin-ms.net4.5Ef6.zip e si deve cambiare

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

a

<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql" /> 
+0

Mi ci è voluto un po 'per capirlo da solo - ho dovuto andare nella console del gestore pacchetti e usare "Install-Package npgsql -Pre", anche di d che su entity-framework, grazie per aver confermato che avrei dovuto farlo solo per npgsql. –

+2

Utilizzo di NpgSql dal file zip qui (2.0.13.91) Infatti non lancia l'eccezione DbProvider ma genera molte altre strane eccezioni nelle query. EF6 e NpgSql 2.0.14.3 Sono ora disponibili su nuget senza usare -pre. Ma ricado ancora alla stessa eccezione di cui sopra. Entrambe le versioni stabile EF e NpgSql sono state rilasciate e deve esserci una soluzione! –

3

ho preso EF6 e Npgsql lavorare seguente:

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) 

E questi vanno in 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> 
1

Questo è un modello App.config che può essere utilizzato come punto di partenza.

<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" /> 
     </configSections> 
     <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
     </startup> 
     <entityFramework> 
     <providers> 
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework"></provider> 
     </providers> 
     <defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" /> 
     </entityFramework> 
     <system.data> 
     <DbProviderFactories> 
      <remove invariant="Npgsql" /> 
      <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" /> 
     </DbProviderFactories> 
     </system.data> 
    </configuration> 

Nota che sarà necessario l'assemblaggio Npgsq.EntityFramework.dll 2.1.0 e 2.1.0 Npgsql Entrambi sono attualmente in beta e si può trovare in Nuget o http://downloads.npgsql.org o nella nostra pagina del progetto github: https://github.com/npgsql/Npgsql/releases.

ho appena scritto un post su di esso: http://fxjr.blogspot.com.br/2014/02/using-entity-framework-6-with-npgsql-210.html

spero che aiuta.

1

Questo è quanto ho capito di lavoro:

installare il pacchetto

Installare-Pacchetto Npgsql.EF6 -Pre

E dopo che aggiungere questa riga al web.config

<system.data> 
    <DbProviderFactories> 
    <remove invariant="Npgsql" /> 
    <add name="Npgsql Data Provider" invariant="Npgsql" support="FF"   description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" /> 
    </DbProviderFactories> 
</system.data> 
Problemi correlati