2

PostgreSQL에서 EF 마이그레이션을 사용할 수있는 opensource PostgreSqlMigrationSqlGenerator 라이브러리의 지원을 완료하기 위해 Npgsql 2.0.14.3을 사용하여 Entity Framework 6 마이그레이션을 테스트하려고합니다.Npgsql을 사용하는 EF6 마이그레이션에서 DbProviderServices 오류가 발생합니다.

내가 쓰고 있어요 테스트 클래스는이 (click here for github page)입니다 :

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code 

Additional information: 
The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql, Version=2.0.14.3, 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. 

내가 앱을 추가 :

using System.Data.Entity.Infrastructure; 
using System.Data.Entity.Migrations; 
using System.Data.Entity; 
using System.Data.Entity.Migrations.Sql; 
using Npgsql; 
using NUnit.Framework; 

namespace EntityFramework.PostgreSql.Test.IntegrationTests 
{ 

    [TestFixture] 
    public class PostgreSqlMigrationSqlGeneretorHistoryTest 
    { 

     private const string ConnectionString = "Server=127.0.0.1;Port=5432;Database=testEF6;User Id=postgres;Password=p0o9i8u7y6;CommandTimeout=20;Preload Reader = true;"; 
     private const string ProviderName = "Npgsql"; 


     [Test] 
     public void GenerateInsertHistoryOperation() 
     { 


      var migrator = new DbMigrator(new LocalMigrationConfiguration()); 

      migrator.Update(); 


     } 

     public class LocalMigrationConfiguration : DbMigrationsConfiguration<LocalPgContext> 
     { 
      public LocalMigrationConfiguration() 
      { 
       AutomaticMigrationDataLossAllowed = true; 
       AutomaticMigrationsEnabled = false; 
       SetSqlGenerator("Npgsql", new PostgreSqlMigrationSqlGenerator()); 
       MigrationsNamespace = "EntityFramework.PostgreSql.Test.IntegrationTests.Migrations"; 
       MigrationsAssembly = typeof (LocalPgContext).Assembly; 
       TargetDatabase = new DbConnectionInfo(ConnectionString, ProviderName); 
      } 
     } 

     public class LocalPgContext : DbContext//, IDbProviderFactoryResolver, IDbConnectionFactory 
     {/* 
      public DbProviderFactory ResolveProviderFactory(DbConnection connection) 
      { 
       return DbProviderFactories.GetFactory("Npgsql"); 
      } 

      public DbConnection CreateConnection(string nameOrConnectionString) 
      { 
       return new NpgsqlConnection(nameOrConnectionString); 
      }*/ 
     } 
     /* 
     public class LocalConfiguration : DbConfiguration 
     { 
      public LocalConfiguration() 
      { 

       // can't set this cos NpgsqlServices is internal 
       SetProviderServices(
        "Npgsql", provider: NpgsqlServices.Instance 
        ); 
      } 

     } 
     */ 
    } 
} 

하지 않습니다 GenerateInsertHistoryOperation 시험 방법은이 오류를 반환 그것을 렸기 때문에 초기화 .confing 파일을 사용하여 공급자를 설정하십시오 (github link) :

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false" /> 
    </configSections> 
    <entityFramework> 
    <providers> 
     <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql" /> 
    </providers> 
    </entityFramework> 
</configuration> 

Npgsql 2.0.14.3이 여전히 EF6을 지원하지 않는지, 아니면 코드에서 뭔가 빠졌는지 알 수 없습니다.

Click here to see it on github

감사합니다.

나는 당신이 필요로하는 npgsql 버전은 최신 베타 버전입니다 생각 불행하게도

EF (6)을 사용하는 내 최신 프로젝트에 매우 유용 할 것이다 PostgreSQL의 마이그레이션과 같은 완성 된 프로젝트를보고 사랑이를 사용하려고 할

답변

2

패키지 관리자의 라인을 사용하여 npgsql의 EF 6 버전을 설치하십시오.

Install-Package Npgsql.EF6 -Pre 
+0

작동합니다! 이제 나는 다른 사람들의 문제를 찾고 있지만 짧은 시간 안에 잘 작동하는 버전을 얻길 바랍니다. –

+0

좋아요! 내가 그걸로 너를 도울 수 있다는 소식을 듣고 기쁘다. –