Entity Framework 5.0 PostgreSQL (Npgsql) default connection factory

烂漫一生 提交于 2019-12-03 06:30:33

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!