Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9273801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:11:56+00:00 2026-06-18T16:11:56+00:00

I’m trying to get EF 5.0 code first working with PostgreSQL (Npgsql provider). I

  • 0

I’m trying to get EF 5.0 code first working with PostgreSQL (Npgsql provider). I have Npgsql 2.0.12.1 installed via NuGet (referenced assembly is 2.0.12.0 though).
I have Npgsql declared in app.config (both default connection factory and provider factory):

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

I have following test running successfully :

[Test]
public void DatabaseConnection_DatabaseFactoryTest()
{
    var factory = DbProviderFactories.GetFactory("Npgsql");
    var conn = factory.CreateConnection();
    conn.ConnectionString = _connectionString;
    var npg = (NpgsqlConnection)conn;
    var result = TestConnectionHelper(npg); // scalar select version(), nothing particular
    Assert.AreEqual(result, "PostgreSQL 9.2.2, compiled by Visual C++ build 1600, 64-bit");            
}

That means at least database instance is running and provider is configured successfully.
Now what i want is to use custom database context inherited from DbContext which will be tied to same provider and initialized via connection string :

public class InventoryContext : DbContext
{
    public InventoryContext(string nameOrConnectionString) : base(nameOrConnectionString)
    {
    }
    // mappings and properties, cut for conciseness
}

Following test fails :

[Test]
public void DatabaseConnection_DatabaseContextTest()
{
    using (var ctx = new InventoryContext(_connectionString))
    {
        //var db = ctx.Database;
        ctx.InventoryObjects.Add(_inventoryObject); // exception here
        ctx.SaveChanges();
    }
}   

It says

Failed to set Database.DefaultConnectionFactory to an instance of the 'Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' type as specified in the application configuration. See inner exception for details.

Inner exception is InvalidOperationException :

{"Constructor for type \"Npgsql.NpgsqlFactory\" is not found."}

I guess there is a problem with connection string (it does not contain Npgsql provider) :

"Server=127.0.0.1;Port=5432;User Id=postgres;Password=p4ssw0rd;Database=InventoryDatabase;";

What is the most elegant way to solve this problem programmatically? Just tried passing connectionString from app.config to context’s constructor, it works.
edit
Uploaded test project to Dropbox – VS2012 solution, 10 mb

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:11:57+00:00Added an answer on June 18, 2026 at 4:11 pm

    Dug deeper into the problem, found out that it is caused by that fact that Npgsql is referencing EntityFramework 4.4.0 assembly. Solved as follows :

    1. Added EF Nuget package to test project (which is build against FW 4.5);
    2. Manually added reference to EntityFramework.dll version 5 in Npgsql2010 project (Nuget adds 4.4.0 by default);
    3. Changed assembly binding in Npgsql app.config to “EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”;
    4. Fixed described above “Constructor for type “Npgsql.NpgsqlFactory” is not found error by making constructor public;
    5. Fixed following error “Unable cast NpgsqlFactory to IDbConnectionFactory” by implementing IDbConnectionFactory interface on NpgsqlFactory :

      using System.Data.Entity.Infrastructure;
      …
      public sealed class NpgsqlFactory : DbProviderFactory, IServiceProvider, IDbConnectionFactory
      …
      public DbConnection CreateConnection(string nameOrConnectionString)
      {
      return new NpgsqlConnection(nameOrConnectionString);
      }
      d

    Now i’m experiencing “Error: 3F000: schema “dbo” doesn’t exist” which is related to EF. I have mapping to PostgreSQL standard public schema in DbContext’s OnModelCreating : modelBuilder.Entity().ToTable(“TableName”, “public”) though. Looking forward to solution of this problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.