【问题标题】:EF7 RC1 The term 'Scaffold-DbContext' is not recognizedEF7 RC1 无法识别术语“Scaffold-DbContext”
【发布时间】:2016-06-07 00:27:23
【问题描述】:

我正在尝试使用 EF7 RC1 按照以下说明从现有数据库中搭建脚手架 https://media.readthedocs.org/pdf/ef/latest/ef.pdf

当我从包管理器控制台运行命令时

Scaffold-DbContext -provider EntityFramework.MicrosoftSqlServer -connection "Server=(localdb)\MSSQLLocalDB;Initial Catalog=Clients_Local;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"

我收到此错误

Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Scaffold-DbContext -provider EntityFramework.MicrosoftSqlServer -conn ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Scaffold-DbContext:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

我的 project.json 看起来像这样

{
  "userSecretsId": "aspnet5-WebApplication1-1702fb51-ff21-46b5-8685-eb0834dd86f0",
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

在研究了这个问题后,我删除了 C:\Users\.dnx\bin 的内容并使用

更新了 dnvm

https://github.com/aspnet/Home#cmd

但我仍然遇到同样的错误。

【问题讨论】:

标签: entity-framework entity-framework-core


【解决方案1】:

看起来您必须使用 dnx 命令,而不是包管理器控制台,如 RC1 文档中所述:http://docs.efproject.net/en/latest/getting-started/aspnet5/existing-db.html


更新:EF 文档已经移动了一点。现在可以在这里找到 dnx 命令: http://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html

如果它再次移动,这里是相关命令:

dnx ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" EntityFramework.MicrosoftSqlServer --outputDir Models

【讨论】:

    【解决方案2】:

    对于 RC2,语法/CLI 发生了变化。您基本上可以按照此处的说明进行操作:https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html,但我不得不使用这些命令来生成脚手架。

    我从命令行运行这些,而不是从包管理器控制台。

    您可以使用它来检查参数和选项:dotnet ef dbcontext scaffold --help

    示例: dotnet ef dbcontext scaffold "Server=(LocalDB)\MSSQLLocalDB;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -c BloggingContext -o BloggingModels

    【讨论】:

      【解决方案3】:

      我发现正确的解决方法是安装 Powershell 5 并重新启动。请注意,DNX 命令也已替换为 dotnet 命令。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      • 2020-02-14
      • 2020-03-03
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多