简体   繁体   English

带有Npgsql的实体框架6

[英]Entity Framework 6 with Npgsql

I want to use Entity Framework 6 with PostgreSQL in ASP.NET MVC 4 project. 我想在ASP.NET MVC 4项目中使用Entity Framework 6和PostgreSQL。 I got Entity Framework 6.0.2 + Npgsql 2.0.14.3, but I get error. 我得到了Entity Framework 6.0.2 + Npgsql 2.0.14.3,但是我收到了错误。 How do I fix this? 我该如何解决?

Error: 错误:

An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code mscorlib.dll中出现“System.InvalidOperationException”类型的异常,但未在用户代码中处理

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'. 附加信息:实体框架提供程序类型'Npgsql.NpgsqlServices,Npgsql,Version = 2.0.14.3,Culture = neutral,PublicKeyToken = 5d8b90d52f46fda7'的'Instance'成员未返回继承自'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; 这可能是因为提供者不支持实体框架6或更高版本; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information. 有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882

Web.config 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>

I needed to install Npgsql like this: 我需要像这样安装Npgsql:

Install-Package Npgsql.EF6 -Pre

It installs different version which works. 它安装了不同的版本。

UPDATE: I found that for newer beta version you can write 更新:我发现对于较新的测试版,你可以写

install-package Npgsql.EntityFramework -pre

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM