.NET Database

.NET Entity Framework Code First Migrations — From Zero to Expert

Entity Framework Code First in .NET: migrations, DbContext, generic repository and OpenAPI in 7 practical lessons with SQL Server.

Course description

Entity Framework Migrations, Explained Properly

If you work with .NET and Entity Framework, sooner or later you'll face migrations: that powerful but sometimes mysterious mechanism that keeps your C# code in sync with the database schema. In this course I tackle them from the beginning, using the Code First approach: define your models in C#, and let EF handle the database.

What You'll Learn in 7 Lessons

  • Code First and first migrations: how to configure the project, create your first models and generate the first migration from scratch
  • SQL Server connection string: correct configuration in appsettings.json and environment management
  • Class mapping with ORM: how EF maps your C# entities to database tables
  • DbContext and migration update: setting up the context and applying migrations with dotnet ef
  • OnModelCreating and unique constraints: extending the model with fluent configurations and unique fields
  • Generic repository and Dependency Injection: structuring the data layer in a clean and testable way
  • Service, Controller and OpenAPI: wiring everything together into a documented, working REST API

Who This Course Is For

For those who already know C# and have built something with .NET, but have never approached migrations systematically — or have used them by copying commands without fully understanding them. The level is intermediate: we don't start from scratch on .NET, but we dive deep into a specific tool that makes a real difference in production.

Hands-On Approach

Each lesson builds on the previous one: starting from an empty project and ending with an API with a database managed by EF, a generic repository and integrated OpenAPI documentation. Under an hour, no fluff.

Lessons list
1/7 Introduction to Code First and Migrations

I'll show you how to set up a .NET project using the Code First approach and create your first migration from scratch with Entity Framework — the starting point for keeping your database in sync with your C# code.

Contenuto riservato Accedi
2/7 Configuring the SQL Server Connection String

Let's explore how to properly configure the SQL Server connection string in appsettings.json, handling development and production environments without hardcoding credentials.

Contenuto riservato Accedi
3/7 Class Mapping — Enabling ORM with Entity Framework

I'll explain how Entity Framework maps your C# classes to database tables via ORM — understanding this mechanism is essential to getting the most out of the Code First approach.

Contenuto riservato Accedi
4/7 Setting Up the DbContext and Applying the First Migration

We'll configure the DbContext, wire up the entities, and apply the first migration using dotnet ef — the operational core of Entity Framework Code First.

Contenuto riservato Accedi
5/7 Expanding the Model and Adding Unique Constraints with OnModelCreating

Let's explore how to use OnModelCreating with the Fluent API to customize the model: I'll show you how to add unique constraints, configure relationships, and extend the schema without touching the entity classes.

Contenuto riservato Accedi
6/7 Implementing a Generic Repository and Injecting the DbContext

I'll show you how to implement a generic repository using the IRepository interface and inject the DbContext via Dependency Injection — building a clean and testable data layer.

Contenuto riservato Accedi
7/7 Creating Services, Controllers, and OpenAPI Documentation

We'll connect everything together: I'll create the service layer, the API controller, and configure OpenAPI to produce a fully documented and functional REST API built entirely with Entity Framework Code First.

Contenuto riservato Accedi
Giovanni Pace

Giovanni Pace

Ingegnere Informatico · Pratola Peligna

  • 107 Courses
About the teacher

Sono un ingegnere informatico con oltre 15 anni di esperienza nel settore ICT. Mi occupo di sviluppo software, cybersecurity, data science e intelligenza artificiale, con particolare attenzione all’innovazione e all’automazione dei processi aziendali. Da anni svolgo anche attività di docenza e formazione, creando percorsi pratici e coinvolgenti su programmazione, DevOps, AI e sicurezza informatica.

Accedi per acquistare il corso

Questo corso richiede un accesso dedicato. Accedi o crea un account studente per completare l'acquisto.

This course includes

  • Lessons 7
  • Duration 1h 0m
  • Difficulty intermedio
  • Language it
  • Certificate No

Recently viewed