EF7 RC1无法识别“Scaffold-DbContext”一词

时间:2015-11-19 05:12:33

标签: entity-framework entity-framework-core

我正在尝试使用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

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

3 个答案:

答案 0 :(得分:2)

看起来您必须使用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

答案 1 :(得分: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

答案 2 :(得分:1)

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