【问题标题】:After Core 3.0 upgrade, impossible to add-migration with EF Core 3.0Core 3.0 升级后,无法使用 EF Core 3.0 添加迁移
【发布时间】:2019-09-27 12:16:34
【问题描述】:

升级 core 3.0 后,无法在包管理器中添加迁移。 是我的错

PM> Add-Migration UpdateAlertTable -Context OozymContext
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.ProductInfo' from assembly 'Microsoft.EntityFrameworkCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(Object reportHandler, IDictionary args)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String dataDirectory, String rootNamespace, String language)
   at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor()
   at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute()
   at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0()
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Exception has been thrown by the target of an invocation.

【问题讨论】:

标签: c# .net .net-core-3.0 ef-core-3.0


【解决方案1】:

升级到 3.0 版后我遇到了同样的问题。看完this,我安装了Microsoft.EntityFrameworkCore.Design nuget包,问题解决了。

【讨论】:

  • 我已经有Microsoft.EntityFrameworkCore.Design 3.0.0版本,没有预览版。
  • 我把那个包放到数据库连接字符串所在的项目中,迁移开始工作。
  • 我遇到了同样的问题,当我将 Microsoft.EntityFrameworkCore.Design nuget 包安装到启动项目(有我的连接字符串)中后它就消失了,我所有的问题都消失了!
【解决方案2】:

我在具有数据库连接字符串的链接项目中引用了 Microsoft.EntityFrameworkCore 版本 2.2.6。我升级了,它工作正常

【讨论】:

    【解决方案3】:

    包管理器控制台中的命令已更改。根据 Nuget Gallery 参考。 跟随下面。

    Add-Migration
    Drop-Database
    Get-DbContext
    Scaffold-DbContext
    Script-Migrations
    Update-Database
    

    【讨论】:

      【解决方案4】:

      就我而言,根本原因是 NuGet 中具有不同 EF 版本的链接项目。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-25
        • 1970-01-01
        • 2020-01-29
        • 1970-01-01
        • 2021-01-15
        • 1970-01-01
        • 2020-03-29
        • 1970-01-01
        相关资源
        最近更新 更多