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

后端 未结 4 1756
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 06:36

I\'m trying to create a small POC for my boss about the hybrid of npgsql 12 and ef6, created a new project on visual studio created a sample database created the correspondi

相关标签:
4条回答
  • 2020-12-16 06:41

    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>
    
    0 讨论(0)
  • 2020-12-16 06:53

    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" />
    
    0 讨论(0)
  • 2020-12-16 07:01

    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.

    0 讨论(0)
  • 2020-12-16 07:08

    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>
    
    0 讨论(0)
提交回复
热议问题