-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reverse-Engineer in RC2: Scaffold-DbContext not working on ASP.NET Core project #5376
Comments
This is likely a powershell issue. Try using single quotes around the connection string. |
Same issue:
The exact same format works for a Full .NET Console application |
Can you add |
Ah, yep that was helpful, we should quote the connection string when we pass it to dotnet ef.
You can double quote like this and things work.
|
Adding docs to workaround dotnet/efcore#5376 for RC2.
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:
Yields:
|
Not sure if this is related, but I get this message in the PMC after installing RC2: |
@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 #5292 @DamianReeves weird. We had a similar bug #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
|
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 |
Nate, Thanks for the quick response, greatly appreciated. I had just installed: DotNetCore.1.0.0.RC2-VS2015Tools.Preview1.exe Restarted VS, and created a new core web api project, ported all my code My previous version of the api project used: dnx ef dbcontext scaffold -c "ApplicationDbContext" -o "DBModels" For new project went to package manager console and entered: PM> Scaffold-DbContext -Connection Interesting: if you just type Scaffold-DbContext, you get prompted for I get no stack trace. I also copy in example Scaffold-DbContext samples from this thread, all In addition if I add --verbose to my command I get: PM> Scaffold-DbContext -Connection
I'm not familiar with your suggestion to try using dotnet ef (core way of T On Wed, May 18, 2016 at 4:06 PM, Nate McMaster [email protected]
Todd Greenwald |
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):
|
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: 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: Now, the error I'm getting is: |
To get extra information which is helpful to us when debugging, when executing Note to self: the following classes of connection strings (and combinations) should be tested:
|
@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 #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.
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 |
@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: |
Also, @saf-itpro Can you check if "dotnet.exe" is on your path? |
And, what is your powershell version? |
@natemcmaster running your powershell version command I'm getting following: 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: 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: 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) In my project.json i've added: "tools": { 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'. 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: |
@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. dotnet/EntityFramework.Docs@a6868fb |
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": {}
}
}
|
|
Not Able to Scaffold the DBContext: Command:Scaffold-DbContext "Server=dv7\SQLExpress;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -outputdir Models Getting the Below Error: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. Power Shell VersionOther Details:Visual Studio 2015 |
@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. Just for knowing, will the scaffolding not work with VS2015? Tools Version"Microsoft.EntityFrameworkCore.SqlServer": "1.1.1", |
I appreciate any help. PM> Scaffold-DbContext "'Server=XXXXXXXX;database=XXXXXXXX;Trusted_Connection=True;'" Microsoft.EntityFrameworkCore.SqlServer -Verbose |
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.
The text was updated successfully, but these errors were encountered: