安装Microsoft.EntityFrameworkCore,版本= 5.0.0.0后无法支持DBContext

时间:2020-09-14 07:22:24

标签: asp.net-core entity-framework-core dbcontext

所以我最近安装了 Entity Framework Core 5.0 Preview 3 ,因为我需要使用过滤的包含。

源: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

但我仍然遇到异常。 我该怎么办?我喜欢“包含过滤条件”,所以我不想卸载最新的efcore预览。

1 个答案:

答案 0 :(得分:1)

因此,我回头阅读了该问题中引用的文章,并尝试使用 developer命令提示符而不是程序包管理器控制台来搭建DBcontext。 我执行了以下命令:

-> UPDATE wp_posts SET post_content = REPLACE(post_content,'www. shop.mysite.com/wp-content/','images.mysite.com/')

,它没有任何问题。 但我仍然不明白为什么会这样。