Tuesday, February 25, 2014

Npgsql 2.1 Release Candidate 1 released!

Today we released Npgsql 2.1 RC1. This release has very few fixes since Beta1. In fact, only two:

Fixed bugs:

#141 AlwaysPrepare does not works in some cases. Thanks @avb1987.
#153 Fixed wrong comma putting in AddFunctionColumnListSupport(). Thanks @tyler-nguyen.

The changelog of the Beta1 is way bigger and has a lot of information about the changes we made since our last stable 2.0.14 release. You should check it out to see what changed and what new features you will get when you use 2.1.

We will have the final version release in the beginning of March.

Downloads are available on Nuget, github and pgfoundry. You may want to check my previous post about how to get Npgsql 2.1 beta1. The instructions there also apply to 2.1 rc1.

Please, give it a try and let us know what you think. Drop by our user forums to discuss or send your bug reports to our issues section on github. 

Thursday, February 20, 2014

How to get Npgsql 2.1.0 beta

In my last post, I talked about how to use Npgsql 2.1.0 and showed an App.config file which you could use as a template for your applications which use Entity Framework 6.

Npgsql 2.1.0 didn't have a stable release yet. It is currently in beta (and shortly in RC). You can download it from the following sources:


As already mentioned, Npgsql 2.1.0 didn't have a stable release yet, so you will need to ask Nuget to install a pre-release version of Npgsql. You do that with the following nuget command:

PM> Install-Package Npgsql -Pre

If you plan to use Entity Framework 6, you will also need to download the Npgsql.EntityFramework assembly. This is done with the following nuget command:

PM> Install-Package Npgsql.EntityFramework -Pre

If you plan to use Entity Framework 4.x, you will need to download Npgsql.EntityFrameworkLegacy. Install it with the following nuget command:

PM> Install-Package Npgsql.EntityFrameworkLegacy -Pre


You can download zip files of all the assemblies for many .net platform versions in our releases page at GitHub.


You can download zip files of all the assemblies for many .net platform versions in our release pages at pgfoundry.org .

Monday, February 17, 2014

Using Entity Framework 6 with Npgsql 2.1.0

UPDATE (2014-05-19): Marek Beneš noticed a problem in the default connection factory config. It is fixed now. Thanks, Marek!

UPDATE (2014-02-20): I created a new post explaining how to get Npgsql 2.1.0.

Although this post is about EF 6, I'd like to talk about our current situation to support both EF 6 and EF4.x which explain why there are some subtle changes between EF 4.x and EF 6.x App.config settings. 

Support for EF versions 4.x and 6.x

Sometime after we started to work on Npgsql 2.1.0, we started to add code to support EF6 and decided to reorganize our Entity Framework support code. Shay created a pull request to organize this change and isolate the EF code out of core Npgsql code. The result was the creation of two separated assemblies:

  • Npgsql.EntityFramework.dll for EF6 and above;
  • Npgsql.EntityFrameworkLegacy.dll for EF4.x.

Only when using Npgsql with EF6 you will need to reference Npgsql.EntityFramework.dll assembly. This is needed because the EF system has to find it in order to use it.

When using EF 4.x, you won't need to reference Npgsql.EntityFrameworkLegacy.dll. Npgsql will load it using reflection. You just need to make sure the assembly is located at the same place as Npgsql.dll. With this approach, using EF 4.x with 2.1.0 will be the same way as using with previous versions of Npgsql.

In order to facilitate how to configure Npgsql 2.1.0 to work with EF6, I'm pasting* below an App.config template which you can use as a starting point(1).

Configuration settings for EF 6

<xml version="1.0" encoding="utf-8"?>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
 Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework"></provider>
    <defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql" />
      <remove invariant="Npgsql" />
      <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" 
 type="Npgsql.NpgsqlFactory, Npgsql" />

*Sorry for the bad formatting :(

The most important change from previous configuration files is the provider entry which had its type changed from Npgsql.NpgsqlFactory to Npgsql.NpgsqlServices as well as the location of this type which used to be in the Npgsql assembly and now it is located at the Npgsql.EntityFramework assembly.

With those changes, you will be able to use Npgsql 2.1.0 with EF6 without any problem.

Let me know in the comments if you have any problem with those directions.

In a later post I'll show a step by step on how to use Npgsql 2.1.0 with EF 6 and some exciting features we are working on: Support for EFMigration and Database creation and Returning DB generated values on insert for EF


1. Another option to have those configurations set up is to install the Nuget Npgsql.EntityFramework package. Shay added a script which configures the App.config file and add the needed entries in order to make it work with Npgsql.