saranhya narakedamilli saranhya narakedamilli - 10 days ago 5
C# Question

Postgresql with EF6 creation of ddex is failed

I'm trying to to work with Entity Framework 6, and connect it to a Postgresql
database.

I'm using npgsql.Entityframework, but get an error when creating the ddex file.
enter image description here

Can someone knows why?

Thanks.

Answer

Install Npgsql, to work between Entity Framework to PostgreSql:

  1. Download and install the Setup_NpgsqlDdexProvider.exe from https://github.com/npgsql/npgsql/releases.
  2. Open Visual-Studio, click on the tab: TOOLS -> Setup Npgsql DbProviderFactories. A window will open, you need to click OK.

enter image description here

  1. Close Visual-Studio and open as administrator the two machine.config files of .NET with notepad.

There are two file that we need to edit, you can find the file at the paths:

  • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
  • C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config

Add the flowing element to the files:

<system.data>
  <DbProviderFactories>
    <remove invariant="Npgsql"/>
    <add name="Npgsql Data Provider"
         invariant="Npgsql"
         description=".Net Data Provider for PostgreSQL"
         type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
         support="FF" />
  </DbProviderFactories>
</system.data>
  1. Reopen Visual-Studio at the wanted project.
  2. Install Entity Framework through Nuget.
  3. Open the Package Manager Console and insert the commend:

    Install-Package EntityFramework6.Npgsql
    

Check that the wanted DLL are references, like so:

enter image description here

If not add the DLL manually. The sopose to be at the paths:

  • C:\Users\YOURCOMPUTERNAME\documents\visual studio 2015\Projects\PostgreSqlVsEfwDemo\packages\Npgsql.3.0.5\lib\net45\Npgsql.dll
  • C:\Users\ YOURCOMPUTERNAME\documents\visual studio 2015\Projects\PostgreSqlVsEfwDemo\packages\EntityFramework6.Npgsql.3.0.5\lib\net45\EntityFramework6.Npgsql.dll
  1. Open the App.config\Web.config and add two elements:

    • The provider element at entityFramework -> providers. as so:

    • The provider element at DbProviderFactories. as so:

      <system.data>
      <DbProviderFactories>
        <remove invariant="Npgsql" />
      
        <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
      </DbProviderFactories>
      

If the <system.data> element isn't exist, add it all.

  1. Now lets add Entity Data Model like so:
    • Select "EF Designer from database"

enter image description here

  • Click on "New Connection"

enter image description here

  • Choose the "PostgreSQL Database" as the Data source: enter image description here

  • Filled the fields:

    • HOST
    • USERNAME
    • PASSWORD
    • PORT
    • DATABASE (fill this field last.)

enter image description here

  1. Click on "Test Connection" to see if it works.

  2. Continue with Entity Framework as regular.

Hope it's help you.

This document of Npgsql Docs really helped me, but still have problems.

Comments