Using npgsql 12 and ef 6 together - have anyone succeeded with it?

做~自己de王妃 提交于 2019-11-29 02:25:51

Now it only works with last beta version of Npgsql http://pgfoundry.org/frs/download.php/3494/Npgsql2.0.13.91-bin-ms.net4.5Ef6.zip And you must change

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

to

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

I got it EF6 and Npgsql to work following:

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)

And these go into 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>

This is a template App.config which you can use as a starting point.

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

Note that you will need the Npgsq.EntityFramework.dll 2.1.0 assembly as well as Npgsql 2.1.0 Both are currently in Beta and you can find them at Nuget or http://downloads.npgsql.org or in our github project page: https://github.com/npgsql/Npgsql/releases.

I just wrote a blog post about it: http://fxjr.blogspot.com.br/2014/02/using-entity-framework-6-with-npgsql-210.html

I hope it helps.

This is how I got it working :

First install the package

Install-Package Npgsql.EF6 -Pre

And after that add this line to the 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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!