none
Unable to update EntityFramework models from PostgreSQL database (version 9.3) in Visual Studio 2017 RRS feed

  • Question

  •  Our developer group upgraded from Visual Studio 2013 to Visual Studio 2017. we now attempted to update some of our existing "db-first" EntityFramework models from our PostgreSQL database. When doing so, we received the following error.

    An exception of type 'System.ArgumentException' occurred while attempting to update from the database. The exception message is: 'Unable to convert runtime connection string to its design-time equivalent. The libraries required to enable Visual Studio to communicate with the database for design purposes (DDEX provider) are not installed for provider ‘Npgsql’.

    Does anyone has clue how to solve this problem? Thx!

    Thursday, April 11, 2019 7:33 PM

All replies

  • Hi Jane,

    Have you add the reference of "Npgsql.EntityFramework"? Here are some articles maybe you can refer to:

    http://www.npgsql.org/efcore/;

    Code-First Database Design with Entity Framework and PostgreSQL.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 12, 2019 5:45 AM
    Moderator
  • Hi Kyle,

    thanks for providing the above links!

    we use Entity Framework 6.

    so we should reference the link: http://www.npgsql.org/ef6/index.html

    we do reference Npgsql.EntityFramework.dll.

    it works fine in VS2013. However it does not work for VS2017.

    we see the following link: 

    https://stackoverflow.com/questions/53701136/how-to-setup-postgresql-with-visual-studio-2017-or-net-4-5

    we still not fully figure out yet.

    Tuesday, April 16, 2019 8:10 PM
  • EF 6 DB first is the last format in the way EF builds the persistence model using a EDMX. EF Core code first or DB first do not use an EDMX.

    Your alternative approach is to start use using EF 6 code first and build the model classes manually without the usage of migrations.

    Tuesday, April 16, 2019 9:28 PM
  • Hi Jane,

    I am afraid this is a issue about npgsql, which is a third-party dll. And this forum is discussing questions about Microsoft products and services. Maybe you can try submit this issue on GitHub: https://github.com/npgsql/npgsql/issues.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 25, 2019 5:37 AM
    Moderator
  • We found the following links which help us understand what we should be careful.

    We found the solution and provide detail instructions at the end of issue 1775.

    The limitation is that we have to use old version of Npgsql 3.2.7 to make it work with PostgreqSql database 9.3.

    General information about Npgsql

    http://www.npgsql.org/doc/index.html

    Information about Visual Studio Integration (Npgsql.VSIX)

    http://www.npgsql.org/doc/ddex.html

    How to setup NpgsqlDdexProvider 3.2+ [Visual Studio 2015/2017] #1752
    https://github.com/npgsql/npgsql/issues/1752

    How to setup NpgsqlDdexProvider 3.1 #1299
    https://github.com/npgsql/npgsql/issues/1299

    Cannot use EF6 Entity Data Model wizard #1775

    https://github.com/npgsql/npgsql/issues/1775

    Following is detail instructions:

    With Visual Studio 2017, .NET Framework 4.6.1, PostgreSQL 9.3.5

    We  installed :
    1) Npgsql PostGesSql Integration vsix (3.2.7)
    From window explorer, install Npgsql.VSIX 3.2.7 (Npgsql-3.2.7.msi)
    Download from https://github.com/npgsql/Npgsql/releases?after=v4.0.0-rc1
    In VS2017, open Tool=>Extension and Update window, ensure that "Npgsql PostgreSQL Integeration" vesion is 3.2.7" and checkbox "Automatically update this extension" is NOT checked.
    otherwise, after reboot and extension will update to latest version such as "4.3.1.1 (as today 5/11/2020)"
    (then reboot the computer)

    2) Npgsql (3.2.7)
    In VS2017, View=> Other Windows =>Package Manager Console
    Install-Package Npgsql  –Version 3.2.7

    3) EntityFramework6.Npgsql (3.1.1)
    In VS2017, View=> Other Windows =>Package Manager Console
    Install-Package EntityFramework6.Npgsql –Version 3.1.1
    (then reboot the computer)
    the reason we install EntityFramework6.Npgsql 3.1.1 is because its dependency:
    https://www.nuget.org/packages/EntityFramework6.Npgsql/3.1.1
    EntityFramework (>=6.0.0)
    Npgsql (>=3.1.0)
    if install  EntityFramework6.Npgsql 3.2.0, its dependency:
    EntityFramework (>=6.2.0)
    Npgsql (>=4.0.2)

    we have to insure that all Npgsql versions are matched.


    4)  reference: https://www.npgsql.org/ef6/index.html
    To use Entity Framework with Npgsql, define a class that inherits from DbConfiguration in the same assembly as your class inheriting DbContext. Ensure that you configure provider services, a provider factory, a default connection factory as shown below:

    using Npgsql;
    using System.Data.Entity;
    class NpgSqlConfiguration : DbConfiguration
    {
        public NpgSqlConfiguration()
        {
            var name = "Npgsql";
            SetProviderFactory(providerInvariantName: name,
            providerFactory: NpgsqlFactory.Instance);
            SetProviderServices(providerInvariantName: name,
            provider: NpgsqlServices.Instance);
            SetDefaultConnectionFactory(connectionFactory: new NpgsqlConnectionFactory());
        }
    }

    Or reference following link

    https://schneide.blog/2017/09/26/using-postgresql-with-entity-framework/

    add <system.data> section into App.Config:

    <system.data>
        <DbProviderFactories>
          <add name="Npgsql Data Provider"
               invariant="Npgsql"
               description="Data Provider for PostgreSQL"
               type="Npgsql.NpgsqlFactory, Npgsql"
               support="FF"/>
         </DbProviderFactories>
      </system.data>

    either way will work.

    We are able to build EntityFramework data model through Postgre Data provider in VS2017 and get database user table to show on list box.
    Monday, May 11, 2020 6:17 PM