Search⌘ K

Database: Connectivity

Explore how to establish database connectivity in C# using Entity Framework Core. Learn to create models, set up a database context, and use migrations to manage SQL databases while performing CRUD operations in a .NET console application.

What are the databases?

Databases store collections of information in an organized way that can easily be added, deleted, and updated.

How to connect a database with C#

In the following example, a local SQL database is created to demonstrate CRUD (Create, Read, Update, Delete) in a database.

Step 1: Create the project

In the first step, we create a .NET Console Application. In the following, we’re using Program.cs as our project.

Step 2: Verify the Entity Frameworks

In the second step, we verify that the Entity Framework is installed. We require the following three Entity Frameworks:

  1. Microsoft.EntityFrameworkCore 2 Microsoft.EntityFrameworkCore.Tools
...