Thursday, February 6, 2020

How to create a Web API Core and Entity Framework Core Project in Visual Studio Code

Install .NET Core
Use one of the methods below to create a web api project

Run the following command to create a web api project from a template from the command prompt

  • Go to the project location using cd <path>
    • CD C:\Users\david\Documents\\Projects\mot_service
  • Then run following command
    • dotnet new webapi -o theprojectname -f netcoreapp3.1
    • cd theprojectname
  • Then run following command that will open the project in Visual Studio Code
    • code -r ../theprojectname


In visual studio code, Go to Terminal




  • dotnet new webapi -o theprojectname -f netcoreapp3.1


  • Open the project from the editor or run in the terminal :
    • code -r ../theprojectname
Install the following Extensions


Add following packages using the commands in the terminal or command prompt, command palet
 dotnet add package Microsoft.EntityFrameworkCore.Sqlite



  • Command Pallet:


Create your DbContext class and Model classes

Use the following commands to create the database.

  • To add migrations - dotnet ef migrations add InitialCreate
  • To create database - dotnet ef database update
To see the sqllite file use SQL Lite Studio or sqlitebrowser

No comments:

Post a Comment