我试图按照以下说明使用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
但是我仍然遇到同样的错误。
最佳答案
看起来您必须使用dnx命令,而不是Package Manager Console,如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
关于entity-framework - EF7 RC1无法识别术语'Scaffold-DbContext',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33795705/