문제

NPGSQL 2.0.14.3을 사용한 엔티티 프레임 워크 6 마이그레이션을 테스트하여 PostgreSQL을 사용하여 EF 마이그레이션을 사용할 수있는 OpenSource PostgreSqlMigrationSQLGenerator 라이브러리의 지원을 완료했습니다.

복지하는 테스트 클래스는이 ( GitHub 페이지 의 경우 여기를 클릭하십시오 :

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 가이 오류를 반환합니다.

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.
.

Provider ( github 링크 ) :

    <?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을 지원하지 않거나 코드에 뭔가를 놓치지 않으면

GitHub에서 그것을 보려면 여기를 클릭하십시오

감사합니다.

도움이 되었습니까?

해결책

PostgreSQL 마이그레이션이 ef 6을 사용하는 최신 프로젝트에서 매우 유용 할 때 완성 된 프로젝트를보고 싶습니다.

필요한 NPGSQL 버전이 최신 베타 버전이고 패키지 관리자 에서이 행을 사용하여 EF 6 버전의 NPGSQL

을 설치하십시오.
Install-Package Npgsql.EF6 -Pre
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top