Миграции EF6 с Npgsql получают ошибку DbProviderServices

Я пытаюсь протестировать миграции Entity Framework 6 с помощью Npgsql 2.0.14.3, чтобы завершить поддержку моей библиотеки PostgreSqlMigrationSqlGenerator с открытым исходным кодом, которая позволяет использовать миграции EF с Postgresql.

The test class I'm writing is this (нажмите здесь, чтобы перейти на страницу 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.

Я добавил файл App.confing для установки провайдера (ссылка на гитхаб):

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

Спасибо.


person Darion Badlydone    schedule 09.01.2014    source источник


Ответы (1)


Мне бы очень хотелось увидеть завершенный проект, так как миграции PostgreSQL были бы очень полезны в моем последнем проекте, который, к сожалению, использует EF 6.

Я думаю, что нужная вам версия npgsql — это последняя бета-версия, попробуйте использовать эту строку в диспетчере пакетов, чтобы установить версию EF 6 npgsql.

Install-Package Npgsql.EF6 -Pre
person Dominic Lacaille    schedule 12.02.2014
comment
Оно работает! Теперь я нахожу другие проблемы, но я надеюсь получить хорошо работающий релиз в короткие сроки. - person Darion Badlydone; 14.02.2014
comment
Большой! Рад слышать, что я мог помочь вам с этим. - person Dominic Lacaille; 14.02.2014