c# - 执行命令“Scaffold-DbContext”时出现错误“ScriptHalted”
问题描述
我正在尝试计算entity framework
教程“在 Entity Framework Core // entityframeworktutorial.net 中为现有数据库创建模型”-
当我输入命令时:PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
我收到错误:ScriptHalted
使用者:
- Visual Studio - 2019。社区 - 16.3.6;
- 控制台应用程序。核心3.0;
- Microsoft.EntityFrameworkCore - 3.0.0;
- Microsoft.EntityFrameworkCore.Tools - 3.0.0;
故事:
- 我安装了“Microsoft.EntityFrameworkCore - 3.0.0;”
- 我运行命令:PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
- 我收到一个错误:
The name" Scaffold-DbContext "is not recognized as the name of the cmdlet, function, script file, or executable program. Check for correctness.
spelling of the name, as well as the presence and correctness of the path, then try again.
line: 1 character: 19
+ Scaffold-DbContext <<<< "Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True;" Microsoft.EntityFrameworkCore.SqlSe
rver -OutputDir Models
+ CategoryInfo: ObjectNotFound: (Scaffold-DbContext: String) [], CommandNotFoundException
+ FullyQualifiedErrorId: CommandNotFoundException
- 我安装了Microsoft.EntityFrameworkCore.Tools
(根据推荐-“ Scaffold-DbContext'不识别->需要EF工具//github.com ”)`
- 我运行命令:PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
- 我收到一个错误:ScriptHalted
问题。
如何修复“ScriptHalted”错误?
解决方案
我今天遇到了同样的问题,我使用的是 Windows 7。Windows 7 使用 powershell 2.0,所以我将它升级到 5.1,你可以从这里升级它 - https://docs.microsoft.com/en-us/powershell/scripting/安装/安装-windows-powershell?view=powershell-6
升级这个解决了我的问题。我从这里找到了这个解决方案 - https://github.com/aspnet/AspNetCore.Docs/issues/14863