2013-11-25 6 views
6

私はNpgsqlの12とEF6のハイブリッドについての私の上司のための小さなPOCを作成しようとしている、 は、Visual Studio に新しいプロジェクトを作成したが、まだ は、対応するクラスを作成したサンプル・データベースとdbcontext を作成しましたそして、私はfolowingエラーが発生するデータベースにアクセスするためにEFを使用します。npgsql 12とef 6を一緒に使用する - それに成功した人はいますか?私がしようとするたびに

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.

私はそれはかなりの時間のためにサポートされなければならないことを知っている今 http://fxjr.blogspot.co.il/2013/06/initial-ef-6-support-added-to-npgsql.html

を、私はそれを動作させるように見えることはできませんが、 my App.C onfigファイルは次のようになります。

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

何か助けていただければ幸いです!

答えて

3

今では唯一のNpgsql http://pgfoundry.org/frs/download.php/3494/Npgsql2.0.13.91-bin-ms.net4.5Ef6.zip の最後のベータ版で動作し、あなたが

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

私はしばらくそれを理解してくれました。パッケージマネージャコンソールに入り、 "Install-Package npgsql -Pre"私はnpgsqlのためにそれをしていたはずです確認するために、エンティティのフレームワーク上のd。 –

+2

ZipファイルからのそのNpgSqlの使用ここ(2.0.13.91)実際にはDbProvider例外はスローされませんが、クエリではいくつかの奇妙な例外がスローされます。 EF6およびNpgSql 2.0.14.3 -preを使用しないで、ナゲットで使用できるようになりました。 しかし、私はまだ上記の同じ例外に戻ります。 EFとNpgSqlの安定版の両方がリリースされている場合は、解決策が必要です。 –

3

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

を変更する必要があります私はEF6とNpgsqlのは、次のように動作するようにそれを得た:

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) 

そして、これらは、これはあなたが出発点として使用できるテンプレートのApp.configで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

に入ります。

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

あなたはNpgsq.EntityFramework.dll 2.1.0アセンブリが必要になりますだけでなく、Npgsqlの2.1.0は、現在ベータ版でありどちらも、あなたがNugetで、またはhttp://downloads.npgsql.orgまたは当社のgithubのプロジェクトページでそれらを見つけることができます注: https://github.com/npgsql/Npgsql/releases

私はちょうどそれについてのブログ記事を書いた: http://fxjr.blogspot.com.br/2014/02/using-entity-framework-6-with-npgsql-210.html

私はそれが役に立てば幸い。

1

これは、私はそれが働いて得た方法である:

まず、パッケージ

インストール・パッケージNpgsql.EF6 -preを

をインストールし、その後、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> 
関連する問題