执行命令"Scaffold-DbContext"时,出现错误"ScriptHalted"。

4
我正在尝试计算“Entity Framework”教程:在 Entity Framework Core 中为现有数据库创建模型 // entityframeworktutorial.net
当我输入以下命令时:PM> Scaffold-DbContext" Server=.\\SQLEXPRESS1;Database=SCHOOLDB.MDF;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models,我收到了错误消息:ScriptHaltedenter image description here 数据库图片
enter image description here 使用:
   - Visual Studio - 2019. Community - 16.3.6;
   - 控制台应用程序。Core 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 'is not recognized -> require EF Tools // github.com")。

- 我运行命令:PM> Scaffold-DbContext" Server =. \ SQLEXPRESS1; Database = SCHOOLDB.MDF; Trusted_Connection = True; " Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
- 我收到一个错误:ScriptHalted
问题。
如何修复“ScriptHalted”错误?

3个回答

3

1

0

我曾经遇到过同样的错误,一切都正确,包也没有问题,PowerShell 也没有问题。问题是在我将之前在 GitHub 上完成的脚本复制并粘贴到 Visual Studio 包管理控制台时,不知道自己复制了一个看不见的奇怪字符,但这个字符导致了错误。

在复制和粘贴代码或脚本时要小心,因为这可能会发生在你身上。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接