EF7 RC1無法識別“Scaffold-DbContext”一詞

entity-framework entity-framework-core

我按照https://media.readthedocs.org/pdf/ef/latest/ef.pdf上的說明,嘗試使用EF7 RC1從現有數據庫中構建腳手架

從包管理器控制台運行命令時

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

但我仍然得到同樣的錯誤。

一般承認的答案

您似乎必須使用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

熱門答案

對於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



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因