2014-01-11 17 views
12

ASP.NET MVC 4プロジェクトでPostgreSQLとEntity Framework 6を​​使いたいです。私はEntity Framework 6.0.2 + Npgsql 2.0.14.3を取得しましたが、エラーが発生します。これをどうやって解決するのですか?Entity Framework 6 with Npgsql

エラー:

An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code

Additional information: The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql, Version=2.0.14.3, 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.

のWeb.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="DatabaseContext" connectionString="Server=localhost;port=5432;Database=main;User Id=postgres;Password=password;" providerName="Npgsql" /> 
</connectionStrings> 
<entityFramework> 
    <providers> 
    <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql" /> 
    </providers> 
</entityFramework> 
+0

を書くことができることを見出しました。それを見てください:http://stackoverflow.com/a/21839153/246097 –

答えて

22

私はこのようなNpgsqlのインストールに必要な:

Install-Package Npgsql.EF6 -Pre

それが動作する別のバージョンをインストールします。

UPDATE: 私はちょうど別の質問ではそのための答えを作成し、新しいベータ版のためにあなたが

install-package Npgsql.EntityFramework -pre

+0

+1 - どのようにあなたがそれを理解したか分かりませんが、あなたは私に答えをフォローアップすることで時間を節約しました。ありがとう;-) – sheikhjabootie

+0

NpgsqlEntityFrameworkのリファレンスと同様にEF 6サポートを得るために、Npgsql 2.1バージョンの必要性に関するコメントを追加しました。私はそれらの指示が新しいユーザーがより速くそれを得るのを助けることを願っています。ヘッドアップをありがとう! –

+0

もう1つの詳細は、Npgsql 2.1.0から、プロバイダを登録する行は、EF6以上の場合は、または(EF5以下)これは、EFコードを分離されたアセンブリに移動したために必要です。 –

関連する問題