EntityFramework Scaffold-DBContext not recognised

asp.net-core entity-framework-core

Question

I'm very new to the world of .net, looking at trying to port one of my apps to this platform so I've been working through tutorials using the Code First with entity framework connecting to a data source using CRUD operations for data.

I've now got to try and reverse engineer my existing db as I want to try the Database First Approach which will be what we end up using as it already exists. However when I use the Scaffold-DBContext command in the package manager console I get the Scaffold-DBContext is not recognized ...

After a couple of days reinstalling frameworks, updating powershell, working out where csproj files are to make sure references to the tools included the frameworks were OK, and removing nuget cache (basically any info I could find to try and get this working), I realised that if I create a new project with authentication switched off in the project, the Scaffold-DBcontext command seems to work ok. Is there a reference or package I need to install to get this working when I've selected to create a project that will have authentication?

Cheers

1
2
7/27/2017 1:29:37 PM

Accepted Answer

Strange bug indeed,I always used next approach and it worked in all cases. In order to use Scaffold-DBContext with SqlServer you should have 3 packages:

Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.SqlServer.Design
Microsoft.EntityFrameworkCore.Tools

And then use such a line in Package Manager Console:

Scaffold-DBcontext "your connection string" Microsoft.EntityFrameworkCore.SqlServer

If this approach did not work, something seems to be broken in project so please then use -verbose flag like:

Scaffold-DBcontext "your connection string" Microsoft.EntityFrameworkCore.SqlServer -verbose

To get more information about your error. Also sometimes simple dotnet restore command in Package Manager Console helps.

4
7/27/2017 12:43:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow