Learning .NET + Database for the first time can feel like trying to plug your phone charger into the wrong socket . Don't worry, once you know where the plug goes, it's super easy. In this article, we'll learn how to connect an ASP.NET Core MVC app to a SQL Server database using Entity Framework Core (DB-First approach). Think of it like ordering food online:
The Database is the restaurant, EF Core is the Swiggy/Zomato delivery guy, Your App just places the order and waits for the food (data) to arrive
By the end, you'll have a simple working app that talks to your database .
If you want to learn about EF Core, please read the full article at Understanding Entity Framework in .NET
Getting Started with ASP. NET Core MVC + Database-First Approach
So you've just installed Visual Studio and are staring at that "New Project" dialog, thinking:
"How do I make this thing talk to my database… without blowing it up?"
Don't worry. Today, we'll learn DB-First with Entity Framework Core step by step. Think of EF Core as your Uber driver for data:
You don't drive directly to the SQL Server.
You just tell EF Core your pickup point (connection string) and drop-off (models).
It does the heavy lifting.
Step 1. Create / Open an ASP.NET Core MVC Project
Open Visual Studio ---> New Project .NET Core Web App (Model-View-Controller).
Quick refresher on MVC:
Model → Our data (like
Student,Subject).View → The webpage (HTML, CSS).
Controller → The middleman who listens to clicks and fetches data.
Real-world analogy:
Model = Ingredients
Controller = Chef
View = The delicious dish
Step 2. Install Required NuGet Packages
Open Package Manager Console (or terminal).
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Microsoft.EntityFrameworkCore.DesignWhen we set up database connections in .NET, we need a few special packages. EntityFrameworkCore is like the brain of the system that knows how to manage data. SqlServer acts as the translator, helping our app talk clearly with SQL Server. Tools provides us with the scaffold command, making life easier when we need to generate models from our database. And Design allows Visual Studio to work smoothly with EF Core. Without these, our project is like a car without wheels .it looks fancy, but it just won’t move!
Step 3. Scaffold Models + DbContext from Existing Database
The scaffold command reverse-engineers an existing database and generates two things for us automatically:
Entity classes (one class per table — e.g.,
Student.cswith properties that map to table columns.A
DbContextclass (e.g.,ResultDbContextthat containsDbSet<T>properties andOnModelCreatingmapping code.
In short: it turns the database schema into C# classes so we can use LINQ and
DbContextinstead of hand-writing raw SQL.
Before we run the command, make sure:
The project builds successfully (scaffolding reads the project & its packages).
If the project is broken, the scaffold will likely fail. We have the needed NuGet packages in the project

Join the conversation! Your thoughts help the community grow.