EF Core: Scaffold DbContext continues to crash

The official ASP.Net Core says that the following error can be fixed by restarting visual studio:

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. 

However, the team continues to fail.

I run it in the package manager console, following the example provided in the ASP.Net online documentation.

 Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models 
+5
source share
2 answers

This is where I start when I create a new ASP.NET Core 1.1 project that saves a lot of time. If you follow steps 1 and 2, they will not work immediately, try restarting Visual Studio and go to step 2.

Step 1

Use the following project.json command. Recover packages.

 { "version": "1.0.0-*", "dependencies": { "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0", "Microsoft.EntityFrameworkCore": "1.1.0", "Microsoft.EntityFrameworkCore.Design": "1.1.0", "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", "NETStandard.Library": "1.6.1", "Microsoft.NETCore.App": { "type": "platform", "version": "1.1.0" } }, "frameworks": { "netcoreapp1.1": { "imports": "dnxcore50" } }, "tools": { "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final", "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final" } } 

Step 2

Run the query in the package manager console. The following query connects to TestDb db in TestServer

 Scaffold-DbContext "Data Source=TestServer;Initial Catalog=TestDb;Persist Security Info=True;User ID={Username};Password={Password}" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -force -v -t dbo.Table1, dbo.Table2, dbo.Table3 
+2
source

I ran into the same problem. For me it was EntityFrameworkCore.Tools, which was missing and installed incorrectly through NuGet.

Run these commands in the package manager console ( Tools > NuGet Package Manager > Package Manager Console ):

 Install-Package Microsoft.EntityFrameworkCore.SqlServer –Pre Install-Package Microsoft.EntityFrameworkCore.Tools –Pre Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design –Pre 

And then in project.json I added the following:

 "tools": { "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", } 

Important! Make sure this version matches the β€œdependencies (also in project.json). In this example,β€œ 1.1.0-preview4-final ”should also be used in the dependencies.

If the problem still persists, try to restore the ef runtime, the manual is found here: https://github.com/aspnet/EntityFramework/issues/5549

+1
source

Source: https://habr.com/ru/post/1257613/


All Articles