Skip to content

ASPNET Entity Framework Migrations — Managing Database Schema Changes

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you'll learn about ASPNET Ef Migrations. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

EF Core migrations provide a version-controlled way to evolve your database schema alongside your application code.

public class AppDbContext : DbContext
{
    public DbSet<ScanResult> ScanResults => Set<ScanResult>();
    public DbSet<ScanFile> ScanFiles => Set<ScanFile>();
}

public class ScanResult
{
    public int Id { get; set; }
    public string FileId { get; set; } = string.Empty;
    public string Status { get; set; } = string.Empty;
    public DateTime ScannedAt { get; set; }
    public ICollection<Threat> Threats { get; set; } = new List<Threat>();
}

// Migration with seeding
public partial class AddThreatsTable : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable("Threats",
            t => new { Id = t.Column<int>(), Name = t.Column<string>(), Severity = t.Column<string>() },
            constraints: t => t.PrimaryKey("PK_Threats", x => x.Id));
    }
}

Migrations enable safe, repeatable database schema evolution through development, staging, and production environments.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro