EF 6.4 Миграция с. NET Core и ef6.dll дает в NullReferenceException - PullRequest
1 голос
/ 03 апреля 2020

Я создаю пакет миграции для внешнего использования нашей командой базы данных для выполнения миграций Entity Framework. Пакет состоит из проекта Entity Framework (который включает в себя все наши миграции) и инструмента миграции ef6.dll из пакета NuGet Entity Framework 6.4, который находится по адресу ef64package/tools/netcoreapp3.0/any.

Пакет миграции также содержит простой скрипт PowerShell, который выполняет ef6.dll примерно так:

dotnet .\ef6.dll database update --verbose --assembly MyApp.Core.EF.dll --connection-string "Data Source=localhost;Initial Catalog=MyApp;Trusted_Connection=True;" --connection-provider "System.Data.SqlClient"

С использованием migrate.exe (в предыдущих версиях Entity Framework) и ef6.exe для. NET Framework этот пакет работал просто отлично , Но после переключения на. NET Core и ef6.dll выполнение приводит к следующей ошибке:

Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName(String providerInvariantName)
   at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
   at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
   at System.Data.Entity.Internal.LazyInternalConnection.get_Connection()
   at System.Data.Entity.Internal.LazyInternalContext.get_Connection()
   at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo, Func`1 resolver)
   at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbConnectionInfo connectionInfo)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Infrastructure.Design.Executor.CreateMigrator(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Infrastructure.Design.Executor.UpdateInternal(String targetMigration, Boolean force, DbConnectionInfo connectionInfo, String migrationsConfigurationName)
   at System.Data.Entity.Infrastructure.Design.Executor.Update.<>c__DisplayClass0_0.<.ctor>b__0()
   at System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(Action action)
Object reference not set to an instance of an object.

Очень общая c ошибка, но согласно исходному коду EF (https://github.com/dotnet/ef6/blob/02104044fae2aca5d3a1f50f55f4af940a3c64a8/src/EntityFramework/Internal/LazyInternalConnection.cs), похоже, регистрация DbProviderFactory отсутствует или providerInvariantName испорчен в процессе. У меня такое ощущение, что это побочный эффект из-за отсутствующей конфигурации или зависимости. Но до сих пор я не мог понять, как исправить эту ошибку.

Есть идеи о том, как исправить эту ошибку? Также приветствуются другие подходы к созданию автономного пакета миграции.

Заранее спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...