Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 安装Microsoft.EntityFrameworkCore(版本=5.0.0.0)后无法对DBContext进行脚手架搭建_Asp.net Core_Entity Framework Core_Dbcontext - Fatal编程技术网

Asp.net core 安装Microsoft.EntityFrameworkCore(版本=5.0.0.0)后无法对DBContext进行脚手架搭建

Asp.net core 安装Microsoft.EntityFrameworkCore(版本=5.0.0.0)后无法对DBContext进行脚手架搭建,asp.net-core,entity-framework-core,dbcontext,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/ 现在我必须修改数据库中的一个表,自然地,我在PackageManager控制台中执行了以下命令: Scaffold-DbContext "Server=<Server Name>;I

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

资料来源:https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-5-0-preview-3/

现在我必须修改数据库中的一个表,自然地,我在PackageManager控制台中执行了以下命令:

Scaffold-DbContext "Server=<Server Name>;Initial Catalog=<Database Name>;User ID=<user id>;Password=<password>;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Entity -Project <project Name> -force
Scaffold DbContext“服务器=;初始目录=;用户ID=;密码=;”Microsoft.EntityFrameworkCore.SqlServer-OutputDir实体-Project-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)
System.Reflection.TargetInvocationException:调用的目标已引发异常。
--->System.TypeLoadException:无法从程序集“Microsoft.EntityFrameworkCore,Version=5.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”加载类型“Microsoft.EntityFrameworkCore.Internal.SemanticVersionComparer”。
位于Microsoft.EntityFrameworkCore.Design.OperationExecutor..ctor(IOperationReportHandler reportHandler,IDictionary参数)
---内部异常堆栈跟踪的结束---
在System.RuntimeMethodHandle.InvokeMethod(对象目标、对象[]参数、签名符号、布尔构造函数、布尔WrapeExceptions)
在System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr、Binder Binder、Object[]参数、CultureInfo区域性)
位于System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr、Binder Binder、Object[]args、CultureInfo区域性)
在System.Activator.CreateInstance(类型类型、BindingFlags bindingAttr、Binder Binder、对象[]参数、CultureInfo区域性、对象[]ActivationAttribute)
位于System.Activator.CreateInstance(类型,对象[]args)
位于Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(字符串汇编、字符串startupAssembly、字符串projectDir、字符串dataDirectory、字符串根命名空间、字符串语言)
在Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor()中
在Microsoft.EntityFrameworkCore.Tools.Commands.DbContextScaffoldCommand.Execute()中
在Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.c__DisplayClass0_0.b_0()中
在Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(字符串[]args)
位于Microsoft.EntityFrameworkCore.Tools.Program.Main(字符串[]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

但我还是有例外。
我该怎么办?我喜欢筛选Include,因此我不想卸载最新的efcore预览。

因此我回去阅读了我在问题中引用的文章,并尝试使用开发人员命令提示符而不是包管理器控制台来构建DBcontext。 我执行了这个命令:

 `dotnet ef dbcontext scaffold "server=<servername>;database=<database>;user=<user>;password=<password>" Microsoft.EntityFrameworkCore.SqlServ
er --project  "DataAccess" --output-dir "Models" --force`
`dotnet ef dbcontext scaffold“服务器=;数据库=;用户=;密码=;Microsoft.EntityFrameworkCore.SqlServ
呃--项目“数据访问”--输出目录“模型”--强制`
它毫无问题地工作。
但我仍然不明白为什么会出现这种情况。

因此我回去阅读了我在问题中引用的文章,并尝试使用开发人员命令提示符而不是包管理器控制台来构建DBcontext。 我执行了这个命令:

 `dotnet ef dbcontext scaffold "server=<servername>;database=<database>;user=<user>;password=<password>" Microsoft.EntityFrameworkCore.SqlServ
er --project  "DataAccess" --output-dir "Models" --force`
`dotnet ef dbcontext scaffold“服务器=;数据库=;用户=;密码=;Microsoft.EntityFrameworkCore.SqlServ
呃--项目“数据访问”--输出目录“模型”--强制`
它毫无问题地工作。 但我还是不明白为什么会这样