The .NET command-line interface (CLI) is a cross-platform toolchain for developing, building, running, and publishing .NET applications.
Entity Framework (EF) Core is a lightweight, extensible, open source and cross-platform version of the popular Entity Framework data access technology.
This is comprehensive list of all useful commands for EF Core & .Net CLI development.
Entity Framework Core Commands :
dotnet ef can be installed as either a global or local tool. Most developers prefer installing dotnet ef as a global tool using the following command
dotnet tool install --global dotnet-ef
To verify that EF Core CLI tools are correctly installed
dotnet ef
To add your first migration, EF Core will create a migration named InitialCreate:
dotnet ef migrations add InitialCreate
To update the database to the last migration or to a specified migration.
dotnet ef database update
To generate code for a DbContext and entity types for a database. In order for this command to generate an entity type, the database table must have a primary key. You can pass name of connection string as well instead of complete string.
dotnet ef dbcontext scaffold "Server=.\SQLEXPRESS;Database=MyDB;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models
To generates a SQL script from migrations.
dotnet ef migrations script
Dot Net CLI Commands :
To check detailed information about a .NET installation and the machine environment, such as the current operating system
dotnet --info
To check installed .NET SDK versions
dotnet --list-sdks
To check available templates to be run using dotnet new
dotnet new --list
To create a new dotnet core project using the provided template
dotnet new <template>
dotnet new console --framework net6.0 // Example
To restore packages or to update existing packages
dotnet restore
To build the solution
dotnet build solution.sln
To add / remove a NuGet package reference
dotnet add package Newtonsoft.json
dotnet remove package Newtonsoft.json
To run dot net core project
dotnet run