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"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
Version=18.104.22.168, 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.NpgsqlConnectionFactory, 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>
*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.