4
votes

I can't get Scaffold-DbContext to work on a EFCore 1.1 application.

PM> Scaffold-DbContext -Connection "'Server=.;Database=testsite;User Id=sa;Password=Password1234;'" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir EFContext -Context ApplicationDbContext

This is the error that it's giving:

Scaffold-DbContext : Cannot bind argument to parameter 'Path' because it is an empty string. At line:1 char:1 + Scaffold-DbContext + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Scaffold-DbContext], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Scaffold-DbContext

Not exactly a forthcoming error message so I ran just Scaffold-DbContext and it gives me this error after prompting for the Provider. The provider I'm trying to use is Microsoft.EntityFrameworkCore.SqlServer.

2

2 Answers

3
votes

In my case I fixed it installing Microsoft.EntityFrameworkCore.Tools. Make sure to close and reopen VisualStudio. (Do not forget to add the -force flag to the end in order to reapply the changes from scratch) Example:

Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force

So, my dependencies looks like:

Microsoft.AspNetCore.All
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Tools

After that it worked as expected.

1
votes

If you have multiple project in your solution you can try to add the option -StartupProject "nameofyourprojectstartup" with the project name that have to run this command.

I had the same error when trying to run "add-migration" with multiple project (Docker support) in my solution.