1

I have been trying to perform scaffolding on my existing database SQL Server in VS Code software so as to create DBContext and entity domain models. However in VS Code the only available commands are Add Package and Remove Package, I need to run following command in Nuget Package Manager Console.

Is there any other way to do scaffolding in VS Code.

I am running Dot Net Core 3.1 and EF Core 3.1.3. Database is SQL Server and Writing WEB Api using C#

madhaviparopkari
  • 33
  • 1
  • 1
  • 5

2 Answers2

3

For this to work you will need to add following package to vscode using Nuget Package Manager: Add Package command from commandpalatte

Microsoft.EntityFrameworkCore.Tools.DotNet (2.0.3 or latest)

Then do

dotnet restore

Then you need to do following command in terminal window of vscode in directory where your csproj file is, -o specifies the output directory where created domain entity models and dbcontext will reside. Suggest you to create a folder beforehand.

dotnet ef dbcontext scaffold "<your existing db connection string>" Microsoft.EntityFrameworkCore.SqlServer -o Models
Shrikant Prabhu
  • 709
  • 8
  • 13
2

if anyone yet using this thread and If not using Visual Studio as an IDE then you can create, scaffolding globally using

EFCore CLI Tool can be installed by using global dotnet-ef tools.

The CLI tools are cross-platform and easy to use.

Run below command on Command Prompt,

dotnet tool install --global dotnet-ef

Followed by adding below package using CLI (Please use the project location directory to run this command)

dotnet add package Microsoft.EntityFrameworkCore.Design 

Once installed successfully, please verify the installation by running below command as below,

dotnet ef

You are all set !!

Please run the Scaffold-DbContext command to generate required scaffolding as explained above.

For More Please read this forum

Sachin
  • 69
  • 11