entity-framework/core/get-started/overview/first-app.md
In this tutorial, you create a .NET console app that performs data access against a SQLite database using Entity Framework Core.
You can follow the tutorial by using Visual Studio on Windows, or by using the .NET CLI on Windows, macOS, or Linux.
View this article's sample on GitHub.
Install the following software:
dotnet new console -o EFGetStarted
cd EFGetStarted
To install EF Core, you install the package for the EF Core database provider(s) you want to target. This tutorial uses SQLite because it runs on all platforms that .NET supports. For a list of available providers, see Database Providers.
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
Tools > NuGet Package Manager > Package Manager Console
Run the following commands:
Install-Package Microsoft.EntityFrameworkCore.Sqlite
Tip: You can also install packages by right-clicking on the project and selecting Manage NuGet Packages
Define a context class and entity classes that make up the model.
[!code-csharpMain]
EF Core can also reverse engineer a model from an existing database.
Tip: This application intentionally keeps things simple for clarity. Connection strings should not be stored in the code for production applications. You may also want to split each C# class into its own file.
The following steps use migrations to create a database.
Run the following commands:
dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet ef migrations add InitialCreate
dotnet ef database update
This installs dotnet ef and the design package which is required to run the command on a project. The migrations command scaffolds a migration to create the initial set of tables for the model. The database update command creates the database and applies the new migration to it.
Run the following commands in Package Manager Console (PMC)
Install-Package Microsoft.EntityFrameworkCore.Tools
Add-Migration InitialCreate
Update-Database
This installs the PMC tools for EF Core. The Add-Migration command scaffolds a migration to create the initial set of tables for the model. The Update-Database command creates the database and applies the new migration to it.
Open Program.cs and replace the contents with the following code:
[!code-csharpMain]
dotnet run
Debug > Start Without Debugging