Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Visual Studio Design Time Support DDEX Provider

Emill edited this page · 6 revisions

VS2013Pro+NpgsqlDdexProvider+EF6 how to

(by @kenjiuno) Reference: https://github.com/npgsql/Npgsql/pull/213#issuecomment-46892619

Prerequisites:

Install assemblies into GAC

  1. Grab the latest setup program (.exe-file) from https://github.com/npgsql/npgsql/releases and run it.
  2. Select all components to install.

Prepare new project for testing

  1. Launch Visual Studio 2013.
  2. [FILE]→[New]→[Project...]
  3. [Console Application]
  4. Name is [testef] for example.

Install EntityFramework 6, Npgsql and Npgsql.EntityFramework from NuGet

  1. Right click project [testef]
  2. [Managet NuGet Packages...]
  3. Type "EntityFramework" at [Search Online (Ctrl+E)]
  4. Install "EntityFramework". Version is 6.1.1 for now.
  5. Do the same for Npgsql and Npgsql.EntityFramework.

Add EF6 provider into App.config

  1. Open [App.config]
  2. Add provider-element into providers-element.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  ...
  <entityFramework>
    ...
    <providers>
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
      ...
    </providers>
  </entityFramework>
  ...
</configuration>

If you want to be able to run your code on machines that have not installed Npgsql with the installer (or manually added Npgsql and Npgsql.EntityFramework to the GAC and added a Npgsql DbProviderFactory to machine.config) you also need the following:

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

Build once

  1. Build your project.

New ADO.NET Entity Data Model

  1. Right click project [testef]
  2. [Add]→[New Item...]
  3. [ADO.NET Entity Data Model]
  4. Name is [Model1] for example.
  5. Click [Add]
  6. [EF Designer from database] at Choose Model Contents. ef1
  7. [New Connection] at Choose Your Data Connection. ef2
  8. [PostgreSQL Database] at Change Data Source. ef3
  9. Fill properties in Connection Properties. It is easy to fill everything by setting [ConnectionString]. ef4

My sample ConnectionString:

PORT=5432;TIMEOUT=15;POOLING=True;MINPOOLSIZE=1;MAXPOOLSIZE=20;COMMANDTIMEOUT=20;COMPATIBLE=2.1.3.0;HOST=g45;DATABASE=npgsql_tests_ef;PASSWORD=npgsql_tests;USER ID=npgsql_tests;PRELOADREADER=True

Note: Don't forget to set PreloadReader to true.

  1. Select [Yes, include the sensitive data in the connection string.] in this case for easy setup. ef5

  2. Select tables which you want, at Choose Your Database Objects and Settings. ef6

Note: remember the text npgsql_tests_efModel at [Model Namespace].

  1. Click OK for Security Warning. T4 Templates generator warns you as it contains just runnable C# code. ef7

  2. You will get a generated model. ef8

Edit your program.cs

Just my sample code for npgsql_tests_ef database.

About the name of "npgsql_tests_efEntities" class, check your [Model Namespace] entered above. Replace "Model" with "Entities", like it is "npgsql_tests_efModel".

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace testef
{
    class Program
    {
        static void Main(string[] args)
        {
            using (npgsql_tests_efEntities Context = new npgsql_tests_efEntities())
            {
                foreach (Blogs blog in Context.Blogs)
                {
                    Console.WriteLine(blog.BlogId + " " + blog.Name);
                }
            }
        }
    }
}

Sample output: ef10

NpgsqlDdexProvider build tips

(by @kenjiuno) Reference: https://github.com/npgsql/Npgsql/pull/213#issuecomment-42109168

VS2010 users

You'll need VS2010 Professional or greater.

SP0 users:

SP1 users:

If you need newer NpgsqlDdexProvider2010.pkgdef, create your own manually. pkgdef is a kind of registry file for our DDEX registration. Note: It is needed only if you change contents of NpgsqlDataProviderRegistration class.

Command example:

H:\Dev\Npgsql\NpgsqlDdexProvider>"H:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1\VisualStudioIntegration\Tools\Bin\CreatePkgDef.exe" /out=NpgsqlDdexProvider2010.pkgdef /codebase bin\Release-net40\NpgsqlDdexProvider.dll

Output:

Visual Studio (R) PkgDef Creation Utility.
Copyright (c) Microsoft Corporation. All rights reserved.

CreatePkgDef : warning : The Assembly specified at 'bin\Release-net40\NpgsqlDdexProvider.dll' cannot be loaded because an alternate copy with the same identity
exists in the Assembly probing path at 'H:\Dev\Npgsql\NpgsqlDdexProvider\bin\Release-net40\NpgsqlDdexProvider.dll'. The Assembly at 'H:\Dev\Npgsql\NpgsqlDdexPro
vider\bin\Release-net40\NpgsqlDdexProvider.dll' will be loaded instead.
Assembly: NpgsqlDdexProvider 1.0.0.0
Output file: NpgsqlDdexProvider2010.pkgdef

インストールされている製品:   NpgsqlDdexProviderPackage、Version 1.0
パッケージ:          NpgsqlDdexProviderPackage {958b9481-2712-4670-9a62-8fe65e5beea7}
サービス:          PostgreSQL Provider Object Factory

SUCCEEDED:        NpgsqlDdexProvider

Check: How to create a pkgdef file for your Visual Studio Package http://blogs.msdn.com/b/dsvst/archive/2010/03/08/how-to-create-a-pkgdef-file-for-your-visual-studio-package.aspx

VS2012 users

You'll need VS2012 Professional or greater.

VS2013 users

You'll need VS2013 Professional or greater.

How to check if Npgsql DDEX was correctly loaded.

(by @kenjiuno) Reference: https://github.com/npgsql/Npgsql/pull/67#issuecomment-40281835

Here are tips to check.

  • Check your connection dialog: addconn

  • Make sure to edit both x86 and x64's machine.config. VS2013 runs 64bit mode on x64 machine. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config

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

Note that the Version attribute above should match the version of the Npgsql Assembly you are using.

How to debug Npgsql DDEX extension

In order to debug it, you will need to use the Experimental Instance of Visual Studio.

  • In the NpgsqlDdex project, right click and select properties.
  • Go to Debug tab
  • Click on the radio button for Start External Program. Point it to the devenv.exe binary. On my machine it's located at

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe

Then set the command line arguments to /rootsuffix Exp

Save everything and now, just right click the NpgsqlDdex project -> Debug -> Run in a new instance. A new Visual Studio instance should be run where the extension will be made available and you can debug it in the first visual studio instance.

Reference: http://stackoverflow.com/questions/9281662/how-to-debug-visual-studio-extensions

Something went wrong with that request. Please try again.