How do I fix a DbProviderServices inheritance error for a MVC3 project on Mono 3.0.3, Entity Framework 6 Beta2 and Npgsql?

StackOverflow https://stackoverflow.com/questions/14513788

Question

I have a MVC3 project targeting .net 4.5 running on Mono to the point where the only thing that is failing is the connection from Entity Framework to PostgreSQL.

I have an almost identical project working in VS 2012 with MVC4, EF6, Postgres.

I am getting the following error:

System.InvalidOperationException The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must extend from this class and the 'Instance' member must return the Singleton instance of the provider.

Am I missing something in configuration or is this not going to work?

<!--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" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->

And ...

  <entityFramework>
    <providers>
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlFactory, Npgsql">
      </provider>
    </providers>
  </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>

Mono ASP.net version string ...

Version Information: 3.0.3 (master/39c48d5); ASP.NET Version: 4.0.30319.17020
Was it helpful?

Solution 2

I fixed this error.

Change

<entityFramework>
  <providers>
    <provider invariantName="Npgsql" type="Npgsql.NpgsqlFactory, Npgsql"></provider>
  </providers>
</entityFramework>

TO

  <entityFramework>
    <providers>
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql"></provider>
    </providers>
  </entityFramework>

OTHER TIPS

You need a PostgreSQL connector for EF6 because of the changes. you can read more about the situation here:

http://entityframework.codeplex.com/wikipage?title=Rebuilding%20EF%20providers%20for%20EF6

Change you entityFramework section config to this:

<entityFramework>
  <providers>
    <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
  </providers>
</entityFramework>

PS:I using Npgsql version 2.1.0.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top