.NET Development

Your .NET & EF Core Kickstart: A 5-Step Guide for 2025

Ready to build modern apps in 2025? Our 5-step guide kickstarts your journey with .NET and Entity Framework Core, from setup to a working API. Perfect for beginners!

D

Daniel Carter

Senior .NET Developer and architect passionate about clean code and modern application design.

7 min read22 views

Jumping into the .NET ecosystem in 2025 can feel like standing at the base of a mountain. It’s powerful, vast, and the number of paths to the top can be overwhelming. But what if you had a clear, paved trail for your first ascent? That's exactly what this guide is for.

Forget the noise and the endless options for a moment. We're going to build something real, right now. In this guide, we'll walk through five straightforward steps to get you from zero to a functioning .NET Web API that talks to a database using Entity Framework (EF) Core. This is the foundational skill for building almost any modern .NET application.

Whether you're a brand-new developer, a student, or a seasoned pro from another stack, this kickstart is designed for you. Let's get building.

Step 1: Setting Up Your 2025 Development Environment

First things first, we need the right tools. Thankfully, getting started with .NET is easier than ever. We'll need the SDK (the brain), an editor (the workshop), and the EF Core command-line tool (the magic wand).

Install the .NET SDK

Everything starts with the .NET Software Development Kit (SDK). For 2025, we'll be using .NET 9, the latest and greatest. It includes the runtime, compiler, and command-line tools needed to build and run applications.

  1. Head over to the official .NET download page.
  2. Download and install the .NET 9 SDK for your operating system (Windows, macOS, or Linux).
  3. Once installed, open a new terminal or command prompt and run this command to verify the installation:
dotnet --version

You should see an output that starts with `9.x.x`. If so, you're good to go!

Choose Your IDE: Visual Studio 2022 vs. VS Code

You have two fantastic, free options:

  • Visual Studio 2022 Community Edition: A full-featured, powerful Integrated Development Environment (IDE). It's an excellent choice if you're on Windows and want a rich, guided experience with built-in debuggers, test runners, and more.
  • Visual Studio Code (VS Code): A lightweight, fast, and highly extensible code editor that runs everywhere. With the C# Dev Kit extension, it becomes a formidable .NET development environment. This is a popular choice for developers on macOS and Linux, or those who prefer a more minimalist setup.

Pick the one that feels right for you. For this guide, all command-line instructions will work regardless of your choice.

Install the EF Core CLI Tool

Entity Framework Core uses a special command-line interface (CLI) tool to handle database tasks like creating and applying migrations. Install it globally with this single command:

dotnet tool install --global dotnet-ef

If you already have it installed, you can update it with `dotnet tool update --global dotnet-ef`.

Step 2: Scaffolding Your First .NET Project

With our tools ready, let's create our first project. We'll build a minimal Web API—the modern, streamlined way to create HTTP services in .NET.

Navigate to a folder where you want your project to live and run this command:

Advertisement
dotnet new webapi -n MyFirstApi

This command does two things: it creates a new project based on the `webapi` template and places it in a new folder named `MyFirstApi`. Open this folder in Visual Studio or VS Code.

The most important file you'll see is `Program.cs`. In modern .NET, this single file is the entry point and configuration hub for your entire application. It's clean, concise, and where we'll be spending most of our time.

Step 3: Modeling Your Data with C# Classes

Before we can talk to a database, we need to decide what our data looks like. In EF Core, we do this by creating simple C# classes, often called POCOs (Plain Old C# Objects). These classes will be mapped directly to tables in our database.

Let's model a simple `Product`. Create a new folder named `Models` in your project, and inside it, create a new file named `Product.cs`.

namespace MyFirstApi.Models;

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
    public DateTime CreatedAt { get; set; }
}

That's it. EF Core is smart enough to understand that `Id` should be the primary key and will handle auto-incrementing for us. Each property (`Name`, `Price`, `CreatedAt`) will become a column in our `Products` table.

Step 4: Wiring Up EF Core with a DbContext and Migrations

Now we connect our C# model to a real database. This involves three parts: creating a `DbContext`, configuring the connection, and running migrations.

Create the DbContext

The `DbContext` is a special class that represents your session with the database. It's how you'll query and save data. Create a new folder named `Data`, and inside it, a file named `ApiDbContext.cs`.

using Microsoft.EntityFrameworkCore;
using MyFirstApi.Models;

namespace MyFirstApi.Data;

public class ApiDbContext : DbContext
{
    public ApiDbContext(DbContextOptions<ApiDbContext> options) : base(options)
    {
    }

    public DbSet<Product> Products { get; set; }
}

The `DbSet<Product>` property tells EF Core that we want a table for our `Product` model, and we'll access it through `_context.Products`.

Configure the Connection

We need to tell our application which database to use. For simplicity, we'll use SQLite, a file-based database that requires zero setup. First, add the necessary NuGet package:

dotnet add package Microsoft.EntityFrameworkCore.Sqlite

Next, open `appsettings.json` and add a connection string:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=app.db"
  },
  // ... other settings
}

This tells EF Core to create a database file named `app.db` in our project directory.

Finally, we register our `ApiDbContext` with the application's dependency injection container in `Program.cs`. This makes it available anywhere in our app. Add these lines near the top of your `Program.cs` file:

using Microsoft.EntityFrameworkCore;
using MyFirstApi.Data;

var builder = WebApplication.CreateBuilder(args);

// Add this section
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<ApiDbContext>(options =>
    options.UseSqlite(connectionString));

// ... existing services like AddEndpointsApiExplorer and AddSwaggerGen

Create Your First Migration

A "migration" is a file containing C# code that describes changes to your database schema (like creating a table). EF Core uses this to keep your database in sync with your models.

Run this command in your terminal:

dotnet ef migrations add InitialCreate

This creates a new `Migrations` folder with a file that contains the instructions to create our `Products` table. To apply this to the database, run:

dotnet ef database update

And just like that, you have a database! A file named `app.db` should now be in your project folder, complete with a `Products` table.

Step 5: Bringing It All Together: Querying and Saving Data

The setup is done. Now for the fun part: creating API endpoints to interact with our data.

We'll add two minimal API endpoints to `Program.cs`. One to get all products (`GET /products`) and one to create a new product (`POST /products`).

Replace the default `app.MapGet("/weatherforecast", ...)` endpoint in your `Program.cs` with the following code:

// ... after var app = builder.Build();

app.MapGet("/products", async (ApiDbContext context) =>
{
    var products = await context.Products.ToListAsync();
    return Results.Ok(products);
});

app.MapPost("/products", async (Product product, ApiDbContext context) =>
{
    product.CreatedAt = DateTime.UtcNow;
    context.Products.Add(product);
    await context.SaveChangesAsync();
    
    return Results.Created($"/products/{product.Id}", product);
});

app.Run();

Let's break this down:

  • Dependency Injection: Notice how our endpoints simply ask for an `ApiDbContext` in their parameters? The .NET dependency injection container automatically provides it for us. This is modern .NET at its best.
  • GET /products: This endpoint queries the database for all products using `context.Products.ToListAsync()` and returns them as a JSON array.
  • POST /products: This endpoint accepts a `Product` object from the request body, sets its creation date, adds it to the context with `context.Products.Add(product)`, and saves it to the database with `await context.SaveChangesAsync()`.

Run your application now with `dotnet run`. Navigate to `http://localhost:[your_port]/swagger` in your browser. You'll see a beautiful, interactive API documentation page where you can test your two new endpoints right away!

Your Journey Has Just Begun

Congratulations! In just five steps, you've gone from an empty folder to a fully functional .NET 9 Web API connected to a database. You've installed the tools, created a project, modeled data, configured EF Core, and built working API endpoints.

This is the fundamental loop of modern backend development. From here, you can explore more advanced topics like:

  • Adding data validation to your models.
  • Building more complex queries with LINQ.
  • Modeling relationships (e.g., a `Product` has a `Category`).
  • Implementing authentication and authorization.

You've taken the most important step—the first one. Keep experimenting, keep building, and welcome to the .NET community!

Tags

You May Also Like