【发布时间】:2020-12-31 21:46:49
【问题描述】:
所以我最近安装了 Entity Framework Core 5.0 Preview 3,因为我需要使用 Filtered Include。
来源:https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-5-0-preview-3/
现在我不得不更改数据库中的一个表,自然而然地,我在 PackagaManagerConsole 中执行了这个命令:
Scaffold-DbContext "Server=<Server Name>;Initial Catalog=<Database Name>;User ID=<user id>;Password=<password>;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Entity -Project <project Name> -force
通常它工作正常并且 DBContext 已更新。 但是现在我遇到了以下异常:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(IOperationReportHandler 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.DbContextScaffoldCommand.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)
我尝试将这些包更新到最新版本:
Microsoft.EntityFrameworkCore ---> 3.1.8
Microsoft.EntityFrameworkCore.Design ---> 3.1.8
Microsoft.EntityFrameworkCore.Relational ---> 3.1.8
Microsoft.EntityFrameworkCore.SQLServer ---> 3.1.8
Microsoft.EntityFrameworkCore.Tools ---> 3.1.8
但我仍然遇到异常。 我该怎么办?我喜欢 Filtered Include,所以我不想卸载最新的 efcore 预览版。
【问题讨论】:
标签: asp.net-core entity-framework-core dbcontext