我正在嘗試使用現有的SQL Server 2016數據庫創建模型。當運行命令提示符時,如文檔中所示:
PM> Scaffold-DbContext "'Server=techestatevm.southeastasia.cloudapp.azure.com;Database=Blogging;User Id=newuser;Password=pass;'" Microsoft.EntityFrameworkCore.SqlServer -verbose
我收到此錯誤:
工作目錄:E:\ Personal \ TE \ VS Projects \ EFGetStarted.AspNetCore.ExistingDb \ src \ EFGetStarted.AspNetCore.ExistingDb
執行命令:dotnet ef --configuration Debug --build-base-path。\ bin \ dbcontext scaffold''Server = techestatevm.southeastasia.cloudapp.azure.com; Database = Blogging; User Id = newuser; Password = pass;' “
Microsoft.EntityFrameworkCore.SqlServer --verbose
在行:1字符:215
+ ... user; Password = pass;''Microsoft.EntityFrameworkCore.SqlServer --verbo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~表達式或語句中出現意外的標記'Microsoft.EntityFrameworkCore.SqlServer'。
我添加了所有Nuget包。看我的project.json
:
{
"dependencies": {
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.InMemory": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final",
"Microsoft.EntityFrameworkCore.Tools.Cli": "1.0.0-preview1-final",
"Microsoft.EntityFrameworkCore.Tools.Core": "1.0.0-rc2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore": "1.0.0-preview1-final"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net452": { }
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
看起來這是一個文檔問題。文件中提到的建議謹慎是罪魁禍首。刪除外部雙引號修復了該問題。
請注意,連接字符串是雙引號(雙引號內有單引號)。對於更多詳細信息,這是RC2中已知問題的解決方法。