I'm trying to create a small POC for my boss about the hybrid of npgsql 12 and ef6, created a new project on visual studio created a sample database created the corresponding classes and the dbcontext yet, whenever I try and use ef to access the database I receive the folowing error:
The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
I know that it should be supported for quite some time now http://fxjr.blogspot.co.il/2013/06/initial-ef-6-support-added-to-npgsql.html
however I can't seem to get it to work, my App.Config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http:// go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!--<section name="entityFramework" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />-->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlFactory, Npgsql" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="CoolestPGSoft"
connectionString="Server=127.0.0.1;Port=5432;Database=CoolestPGSoft;User Id=postgres;Password=********;"
providerName="Npgsql" />
</connectionStrings>
</configuration>
any help would be appreciated!
Now it only works with last beta version of Npgsql http://pgfoundry.org/frs/download.php/3494/Npgsql2.0.13.91-bin-ms.net4.5Ef6.zip And you must change
to
I got it EF6 and Npgsql to work following:
Entity Framework 6 with Npgsql
And these go into App.config
This is a template App.config which you can use as a starting point.
Note that you will need the Npgsq.EntityFramework.dll 2.1.0 assembly as well as Npgsql 2.1.0 Both are currently in Beta and you can find them at Nuget or http://downloads.npgsql.org or in our github project page: https://github.com/npgsql/Npgsql/releases.
I just wrote a blog post about it: http://fxjr.blogspot.com.br/2014/02/using-entity-framework-6-with-npgsql-210.html
I hope it helps.
This is how I got it working :
First install the package
Install-Package Npgsql.EF6 -Pre
And after that add this line to the web.config