Found when updating this tutorial https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html
I'm guessing this is an issue in the way we hand off parameters to the CLI command that we shell out to.
PM> Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer
The term 'localdb' 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.
This is likely a powershell issue. Try using single quotes around the connection string.
Same issue:
PM> Scaffold-DbContext 'Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;' Microsoft.EntityFrameworkCore.SqlServer
The term 'localdb' 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.
The exact same format works for a Full .NET Console application
Can you add -Verbose and share the output?
Ah, yep that was helpful, we should quote the connection string when we pass it to dotnet ef.
Working directory: C:\Users\rowmil\Documents\Visual Studio 2015\Projects\EFGetStarted.AspNetCore\src\EFGetStarted.AspNetCore.ExistingDb
Executing command: dotnet ef --configuration Debug --build-base-path .\bin\ dbcontext scaffold Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True; Microsoft.EntityFrameworkCore.SqlServer --verbose
The term 'localdb' 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.
You can double quote like this and things work.
PM> Scaffold-DbContext "'Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;'" Microsoft.EntityFrameworkCore.SqlServer -Verbose
We should add quotes when shelling to dotnet ef. Also check for other parameters where this may be an issue (i.e. spaces in output directory).
We do add quotes for spaces. I suppose the fix is to also check for parenthesis.
Can we just always quote specific arguments?
I don't see why not.
Also it seems that it doesn't like when I pass a connection string with a dash ('-') in it, even with the double quote suggestion.
So running:
Scaffold-DbContext "'server=azuredb-east.database.windows.net;database=dev-azuredb-core;User Id=AzureDbUser;Password=password;Encrypt=True;TrustServerCertificate=False;'" 'Microsoft.EntityFrameworkCore.SqlServer' -Verbose
Yields:
Working directory: C:\code\sandbox\dotnet\AzureDbDataModelConsole\EFGetStarted.AspNetCore.ExistingDb
Executing command: dotnet ef - - c o n f i g u r a t i o n D e b u g - - b u i l d - b a s e - p a t h . \ b i n \ d b c o n t e x t s c a f f o l d ''server=azuredb-east.database.windows.net;database=dev-azuredb-core;User Id=AzureDbUser;Password=password;Encrypt=True;TrustServerCertificate=False;'' M i c r o s o f t . E n t i t y F r a m e w o r k C o r e . S q l S e r v e r - - v e r b o s e
At line:1 char:315
+ ... sword=password;Encrypt=True;TrustServerCertificate=False;'' M i c r o ...
+ ~
Unexpected token 'M' in expression or statement.
Not sure if this is related, but I get this message in the PMC after installing RC2:
The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program.
@shrib what version of OS and Visual Studio? If you have Win7 and Powershell 2.0, it's possible installing the EF cmdlets died silently. cref https://github.com/aspnet/EntityFramework/issues/5292
@DamianReeves weird. We had a similar bug https://github.com/aspnet/EntityFramework/issues/5260. Apparently my fix in #5263 didn't completely work. As a workaround you can invoke dotnet-ef directly. You'll need to "cd" to the directory of the project
PS> cd MyProject/
PS> dotnet ef
Ah! Yes...that seems to be the issue. I'm running VS 2015 Update2 with RC2 tooling on Windows 7 running PS 2.
So:
Thank you!
@shrib Upgrade powershell and restart VS. You're hitting one of our known issues.. To workaround, upgrade PowerShell to 5.0. https://www.microsoft.com/en-us/download/details.aspx?id=50395
Perfect... that worked. Thank you @natemcmaster !
I'm getting: Value cannot be null. Parameter name: fileName
to
Scaffold-DbContext -Connection "'Server=.\SS2014;Database=TSICV5;Trusted_Connection=True;'" -Provider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir "DBModels" -Context "ApplicationDbContext"
Any thoughts, critical in switching to core...
@toddtsic can you provide more info. e.g. is there a stack trace?
To get more info, add -Verbose to the command (if you are using the cmdlets) or --verbose if you are using "dotnet ef".
Nate,
Thanks for the quick response, greatly appreciated.
I had just installed:
DotNetCore.1.0.0.RC2-VS2015Tools.Preview1.exe
https://visualstudiogallery.msdn.microsoft.com/c94a02e9-f2e9-4bad-a952-a63a967e3935/file/77371/8/DotNetCore.1.0.0.RC2-VS2015Tools.Preview1.exe?SRC=VSIDE&UPDATE=TRUE
Restarted VS, and created a new core web api project, ported all my code
and was left with tons of errors all related to dbcontext, so moved to
re-create dbcontext and their classes.
My previous version of the api project used:
dnx ef dbcontext scaffold -c "ApplicationDbContext" -o "DBModels"
"Server=.\SS2014;Database=TSICV5;Trusted_Connection=True;"
EntityFramework.MicrosoftSqlServer
For new project went to package manager console and entered:
PM> Scaffold-DbContext -Connection
"'Server=.\SS2014;Database=TSICV5;Trusted_Connection=True;'" -Provider
"Microsoft.EntityFrameworkCore.SqlServer" -OutputDir "DBModels" -Context
"ApplicationDbContext"
Value cannot be null.
Parameter name: fileName
Interesting: if you just type Scaffold-DbContext, you get prompted for
parameters, which also results in :
Value cannot be null.
Parameter name: fileName
I get no stack trace.
I also copy in example Scaffold-DbContext samples from this thread, all
with same result.
In addition if I add --verbose to my command I get:
PM> Scaffold-DbContext -Connection
"'Server=.\SS2014;Database=TSICV5;Trusted_Connection=True;'" -Provider
"Microsoft.EntityFrameworkCore.SqlServer" -OutputDir "DBModels" -Context
"ApplicationDbContext" --verbose
Scaffold-DbContext : A positional parameter cannot be found that accepts
argument '--verbose'.
At line:1 char:1
I'm not familiar with your suggestion to try using dotnet ef (core way of
issuing old dnx type commands?)
T
On Wed, May 18, 2016 at 4:06 PM, Nate McMaster [email protected]
wrote:
@toddtsic https://github.com/toddtsic can you provide more info. e.g.
is there a stack trace?To get more info, add -Verbose to the command (if you are using the
cmdlets) or --verbose if you are using "dotnet ef".—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/aspnet/EntityFramework/issues/5376#issuecomment-220184048
Todd Greenwald
President, TeamSportsInfo.com
[email protected]
410-703-3450
I managed to do it with opening command prompt at the root of the project with following command (just as same as RC1, changing dnx to dotnet):
dotnet ef dbcontext scaffold "Insert your connection string " Microsoft.EntityFrameworkCore.SqlServer --output-dir Your/Dir --verbose
Try with (local) instead of . as server name
@toddtsic I haven't gotten to this issue yet but could you try keeping the quotes around the connection string but removing from all the other parameters?
I'm back in action.
I was missing:
Run Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
Run Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design –Pre
Was successful with:
Scaffold-DbContext -Connection "'Server=.\SS2014;Database=TSICV5;Trusted_Connection=True;'" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir ModelsDB -Context ApplicationDbContext
@DamianReeves why are you quoting the provider name? That is not correct syntax.. @natemcmaster
I've an issue when db to be reversed is not a localDb. Please see here. I included -verbose flag and removed one of the two single quotes at the end of the connection string in the command and got following printed out:
Executing command: dotnet ef --configuration Debug --build-base-path .\bin\ dbcontext scaffold 'Server=MyServer\SQL2012;Database=MyDbName;Trusted_Connection=True;' Microsoft.EntityFrameworkCore.SqlServer --verbose
Now, the error I'm getting is:
The expression after '&' in a pipeline element produced a object that was not valid. It must result in a command name, script block or CommandInfo object.
To get extra information which is helpful to us when debugging, when executing Scaffold-DbContext within the Package Manager Console add -Verbose to the command (just one hyphen at the beginning); when executing from the command line add --verbose (note two hyphens at the beginning). If you're having trouble please post the result from adding the verbose flag here and we'll try to help find workarounds.
Note to self: the following classes of connection strings (and combinations) should be tested:
( and )-@lajones Please see my edited comments above. Moreover, enclosing MyServer with ( and ) did not make any difference giving me the same error unless I'm misunderstanding yous suggestion above.
@saf-itpro For your connection string please try without the single quotes and just keep the double-quotes. We have to quote when the connection string would not be interpreted correctly by powershell (which are, at least, the classes I mentioned above), but yours doesn't contain any of those problems. I'm still not sure why quoting would cause the problem you're seeing but try it and let us know.
@lajones I tried your suggestion above by removing the single quotes. Still the same error. I see @natemcmaster just did some fix and committed it few minute agoe. How do I apply that fix?
I've submitted a fix in https://github.com/aspnet/EntityFramework/pull/5618
In the meantime, I'd like to remind that all PMC is doing right now is forwarding to "dotnet ef". You can workaround this executing dotnet ef directly.
e.g.
cd MyProjectDirectory\
dotnet ef dbcontext scaffold [connectionstring] [providername]
https://docs.efproject.net/en/latest/cli/dotnet.html#dotnet-ef-dbcontext-scaffold
@saf-itpro agree with @natemcmaster above but could you still add the full print out with the verbose flag turned on here though. I don't understand why it should cause an error as I frequently execute with a very similar connection string and see no issue. I'd like to track down what's happening in case we need to add another test case.
Also I see you have MyServer and MyDbName above. These are the real names you are using, correct? Not just placeholders you are using in this issue for the real names?
@natemcmaster Could you please let me know where do I use PS> command. I don't find it in VS2015-->Tools-->NuGet Package Manager. I see only PM> command
@saf-itpro ignore the "PS> " part in my comment above.
@lajones After removing single quotes and adding the verbose flag prints out the following text:
Executing command: dotnet ef --configuration Debug --build-base-path .\bin\ dbcontext scaffold Server=MyWin7MachineName\SQL2012;Database=MyDbName;Trusted_Connection=True; Microsoft.EntityFrameworkCore.SqlServer --verbose
Also, @saf-itpro Can you check if "dotnet.exe" is on your path? Get-Command dotnet
And, what is your powershell version?
$PSVersionTable.PSVersion RC2 had a bug that requires using PS 5.
https://docs.efproject.net/en/latest/cli/powershell.html#error-the-expression-after-in-a-pipeline-element-produced-an-object-that-was-not-valid
@natemcmaster running your powershell version command I'm getting following:
**Major Minor Build Revision
3 0 -1 -1**
@saf-itpro Have talked with @natemcmaster about your problem and we think you are running into https://docs.efproject.net/en/latest/cli/powershell.html#error-the-expression-after-in-a-pipeline-element-produced-an-object-that-was-not-valid as mentioned above. We think that is the problem rather than your connection string. Can you update to Powershell 5 (see details in the link) and let us know if you still see the issue?
@lajones and @natemcmaster Issue RESOLVED. Following your advise on installing version 5 of Powershell on my machine, it works now. I ran the following command (with single quotes around connection string) and it successfully reverse engineered my existing database:
Scaffold-DbContext "'Server=MyWin7MachineName\SQL2012;Database=MyDbName;Trusted_Connection=True;'" Microsoft.EntityFrameworkCore.SqlServer
Please Note 1: _MyWin7MachineName_ and _MyDbName_ are just place holders for my win 7 machine name and my SQL Server Db name respectively. So, users need to put their machine name and Db name accordingly.
Note 2: Without single quotes around connection string I got the following error. So, I had to enclose the connection string with single quotes: The term 'Database=MyDbName' 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.
Many thanks to both of you for helping me and (probably some other readers of this post).
Hi guys,
I'm on the process on testing out ASP.NET Core 1.0. I tried using EF Core but I can't seem to make database-first scaffolding to work.
Here's what I've tried:
Installing the following dependencies:
Microsoft.EntityFrameworkCore.SqlServer(v1.0.0)
Microsoft.EntityFrameworkCore.Tools (v1.0.0-preview2-final)
Microsoft.EntityFrameworkCore.SqlServer.Design (v1.0.0)
In my project.json i've added:
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}
Now when I try running the following command in PMC:
Scaffold-DbContext "'Server=WIN-EHM93AP21CF\SQLEXPRESS;Database=ASPNETCoreSignalRDemo;Trusted_Connection=True;'" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models/DB -verbose
I get the following error:
_Unable to resolve startup project 'Microsoft.PowerShell.Core\FileSystem::\vmware-host\Shared Folders\Documents\Visual Studio 2015\Projects\ASPNETCoreSignalRDemo\src\ASPNETCoreSignalRDemo\ASPNETCoreSignalRDemo.xproj'.
Using startup project 'src\ASPNETCoreSignalRDemo'
Working directory: \vmware-host\Shared Folders\Documents\Visual Studio 2015\Projects\ASPNETCoreSignalRDemo\src\ASPNETCoreSignalRDemo
Executing command: dotnet ef '--startup-project' 'Microsoft.PowerShell.Core\FileSystem::\vmware-host\Shared Folders\Documents\Visual Studio 2015\Projects\ASPNETCoreSignalRDemo\src\ASPNETCoreSignalRDemo' '--configuration' 'Debug' '--build-base-path' '.\bin' 'dbcontext' 'scaffold' '''Server=WIN-EHM93AP21CF\SQLEXPRESS;Database=ASPNETCoreDemoDB;Trusted_Connection=True;''' 'Microsoft.EntityFrameworkCore.SqlServer' '--output-dir' 'Models/DB' '--verbose'
Using target project 'ASPNETCoreSignalRDemo'.
Could not load project 'Microsoft.PowerShell.Core\FileSystem::\vmware-host\Shared Folders\Documents\Visual Studio 2015\Projects\ASPNETCoreSignalRDemo\src\ASPNETCoreSignalRDemo'_
PS: I've already updated PowerShell to version 5 but still getting the same error. Perhaps I missed something.
I'm running on Windows 8.1 using Visual Studio 2015 and upgrated .NET core to RTM
I appreciate any inputs. Thank you.
I was able to make it work using command window by running the following script on the root folder of my app:
dotnet ef dbcontext scaffold "Server=WIN-EHM93AP21CF\SQLEXPRESS;Database=ASPNETCoreDemoDB;Integrated Security=True;" Microsoft.EntityFrameworkCore.SqlServer --output-dir Models/DB
@proudmonkey With commit aaae665 @natemcmaster fixed this so you no longer need the additional single quotes around anything (we automatically do it for you under the covers). As you found - the double quotes are enough.
@rowanmiller I think we need to update the docs at https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html#reverse-engineer-your-model to reflect this.
@lajones good catch on the docs. I've updated them to reflect this. https://github.com/aspnet/EntityFramework.Docs/commit/a6868fbfaf524627b25a8184dc626ed44ed8445d
I'm getting this problem now. Using PS 5.0
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-preview3-final",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": {}
}
}
PM> Scaffold-DbContext "'Server=xxx;Database=xxx;Trusted_Connection=True;'" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Verbose
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 "'Server=xxxo;Database=xxx;Trus ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Scaffold-DbContext:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Scaffold-DbContext is in EF.Tools package. EF.Tools.DotNet package gives you dotnet ef commands.
Not Able to Scaffold the DBContext:
Scaffold-DbContext "Server=dv7\SQLExpress;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -outputdir Models
Startup project 'src\EFGetStarted.AspNetCore.ExistingDb' is an ASP.NET Core or .NET Core project for Visual Studio 2015. This version of the Entity Framework Core Package Manager Console Tools doesn't support these types of projects.

Visual Studio 2015
ASP.Net (.Net Core) Project
@mkalkere Please do not "hijack" existing, closed issues - please specify the exact version of the EF Core packages you are using.
You must upgrade to VS 2017 and csproj with the Tools version you are using (or you can use my graphical tool in my SQLite Toolbox (alos works for SQL Server)
@ErikEJ Sorry for posting in the closed post.
I'll use the SQLLite Toolbox.
Just for knowing, will the scaffolding not work with VS2015?
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.1",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.1",
"BundlerMinifier.Core": "2.4.337",
"Microsoft.ApplicationInsights.AspNetCore": "2.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.1.1",
"Microsoft.AspNetCore.Mvc": "1.1.2",
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.1",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.1",
"Microsoft.AspNetCore.StaticFiles": "1.1.1",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.1",
"Microsoft.Extensions.Configuration.Json": "1.1.1",
"Microsoft.Extensions.Configuration.Abstractions": "1.1.1",
"Microsoft.Extensions.Logging": "1.1.1",
"Microsoft.Extensions.Logging.Console": "1.1.1",
"Microsoft.Extensions.Logging.Debug": "1.1.1",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1",
"Microsoft.NETCore.App": "1.1.1",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0"
I appreciate any help.
I am getting the error below. FYI I am using Parrallel VM
PM> Scaffold-DbContext "'Server=XXXXXXXX;database=XXXXXXXX;Trusted_Connection=True;'" Microsoft.EntityFrameworkCore.SqlServer -Verbose
Unable to resolve startup project 'Microsoft.PowerShell.Core\FileSystem::\mac\home\documents\visual studio 2017\Projects\HPlusApp\HPlusApp\HPlusApp.csproj'.
Using project 'HPlusApp'.
Using startup project 'HPlusApp'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile "Microsoft.PowerShell.Core\FileSystem::\\mac\home\documents\visual studio 2017\Projects\HPlusApp\HPlusApp\bin\Debug\netcoreapp1.1\HPlusApp.deps.json" --additionalprobingpath C:\Users\weezy.nuget\packages --runtimeconfig "Microsoft.PowerShell.Core\FileSystem::\\mac\home\documents\visual studio 2017\Projects\HPlusApp\HPlusApp\bin\Debug\netcoreapp1.1\HPlusApp.runtimeconfig.json" C:\Users\weezy.nuget\packages\microsoft.entityframeworkcore.tools\1.1.1\tools\netcoreapp1.0\ef.dll dbcontext scaffold 'Server=XXXXXXXXX;database=XXXXXXXX;Trusted_Connection=True;' Microsoft.EntityFrameworkCore.SqlServer --json --verbose --no-color --prefix-output --assembly "Microsoft.PowerShell.Core\FileSystem::\\mac\home\documents\visual studio 2017\Projects\HPlusApp\HPlusApp\bin\Debug\netcoreapp1.1\HPlusApp.dll" --startup-assembly "Microsoft.PowerShell.Core\FileSystem::\\mac\home\documents\visual studio 2017\Projects\HPlusApp\HPlusApp\bin\Debug\netcoreapp1.1\HPlusApp.dll" --project-dir "\\mac\home\documents\visual studio 2017\Projects\HPlusApp\HPlusApp" --content-root "\\mac\home\documents\visual studio 2017\Projects\HPlusApp\HPlusApp" --data-dir "Microsoft.PowerShell.Core\FileSystem::\\mac\home\documents\visual studio 2017\Projects\HPlusApp\HPlusApp\bin\Debug\netcoreapp1.1\" --root-namespace HPlusApp
Exception calling "AddFromFile" with "1" argument(s): "'basePath' cannot be an empty string ("") or start with the null character.
Parameter name: basePath"
Most helpful comment
I was able to make it work using command window by running the following script on the root folder of my app:
dotnet ef dbcontext scaffold "Server=WIN-EHM93AP21CF\SQLEXPRESS;Database=ASPNETCoreDemoDB;Integrated Security=True;" Microsoft.EntityFrameworkCore.SqlServer --output-dir Models/DB