如何将 PostgreSql 与 EntityFramework 6.0.2 集成?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20628632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:13:44  来源:igfitidea点击:

How to integrate PostgreSql with EntityFramework 6.0.2?

c#postgresqlentity-framework-6

提问by Shakoor Alam

I am receiving following error

我收到以下错误

The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql, Version=2.0.14.2, 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=260882for more information.

实体框架提供程序类型“Npgsql.NpgsqlServices、Npgsql、Version=2.0.14.2、Culture=neutral、PublicKeyToken=5d8b90d52f46fda7”的“Instance”成员没有返回从“System.Data.Entity.Core.Common”继承的对象.DbProviderServices'。实体框架提供程序必须从此类继承,并且“实例”成员必须返回提供程序的单例实例。这可能是因为提供程序不支持 Entity Framework 6 或更高版本;有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882

Can any one help me

谁能帮我

here is my App.Config File

这是我的 App.Config 文件

<?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" />
  </configSections>
  <connectionStrings>
    <add name="CacsLocal" connectionString="Server=localhost;Database=Kappa;User Id=postgres; Password=xyz;" providerName="Npgsql" />
    <add name="   CacsCentral" connectionString="Server=localhost;Database=KPT1;User Id=postgres; Password=insane1234;" providerName="Npgsql" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>     
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"></provider>
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" />
    </DbProviderFactories>
  </system.data>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

I have Npgsql2 version 2.0.14.2 Entity Framework 6.0.2

我有 Npgsql2 版本 2.0.14.2 实体框架 6.0.2

All the packages are installed through Package Manager by following command

所有的包都通过包管理器通过以下命令安装

Install-Package Npgsql -Pre
Install-Package EntityFramework -Pre

Thanks

谢谢

采纳答案by Francisco Junior

Check out this question: Entity Framework 6 with Npgsql

看看这个问题:Entity Framework 6 with Npgsql

It has the pointers to get it working. I hope it helps.

它有让它工作的指针。我希望它有帮助。