我正在使用EF Core在Visual Studio 2015 Update 3中创建.Net Core 1.0.1 Web API。 我正在尝试从我的Windows 10 Home 64位PC上的本地托管在Sql Server 2016 Express上的数据库进行逆向工程。 我正在学习本教程:https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html#reverse-engineer-your-model
教程说我需要在程序包管理器控制台中运行此命令来对我的模型进行反向工程:
Scaffold-DbContext“Server =(localdb)\ mssqllocaldb; Database = Blogging; Trusted_Connection = True;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
因此,我修改了连接字符串以连接到我的数据库,如下所示:
Scaffold-DbContext“Data Source = DESKTOP-AEAOCON \ SQLEXPRESS; Initial Catalog = propworx; Integrated Security = True;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
然后跑了。但是我收到以下错误:
Scaffold-DbContext:无法识别“Scaffold-DbContext”一词 作为cmdlet,函数,脚本文件或可运行程序的名称。 检查名称的拼写,或者如果包含路径,请验证 路径是正确的,然后再试一次。 在行:1个字符:1 + Scaffold-DbContext“数据源= DESKTOP-AEAOCON \ SQLEXPRESS;初始Ca ... + ~~~~~~~~~~~~~~~~~~ + CategoryInfo:ObjectNotFound:(Scaffold-DbContext:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException
本教程确实提到了以下内容:
如果收到错误,则说明“Scaffold-DbContext”一词不是 被识别为cmdlet的名称,然后关闭并重新打开Visual 工作室。
但我已经做到了这一点而且没有帮助。任何人的想法?
这是我的project.json文件:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}