2014-01-11 174 views
12

我想在ASP.NET MVC 4项目中使用实体框架6与PostgreSQL。我得到了实体框架6.0.2 + Npgsql 2.0.14.3,但我得到错误。我该如何解决?实体框架6与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

它安装不同的版本,其中的作品。

更新: 我发现了新的测试版,你可以写

install-package Npgsql.EntityFramework -pre

+0

+1 - 不知道你是怎么想出来的,但通过跟踪答案,你为我节省了大量的时间。谢谢;-) – sheikhjabootie

+0

我刚刚添加了一些关于需要Npgsql 2.1版本以获得EF 6支持以及NpgsqlEntityFramework的参考的评论。我希望这些方向能帮助新用户加快速度。感谢您的领导! –

+0

另一个细节是,从Npgsql 2.1.0开始,注册提供程序的行必须是:适用于EF6或更高版本或适用于EF5及以下版本。这是必要的,因为我们将EF代码移到了分离的程序集中。 –