Mid
From PDF
EF Core
Entity Framework Core
How do you seed initial data using migrations / EF Core configuration?
Short answer: Use the HasData() method in OnModelCreating(): modelBuilder.Entity<User>().HasData( new User { Id = 1, Name = "Admin" } ); Data is inserted automatically during Update-Database. Changes to seed data require a new migration.
Real-world example (ShopNest)
When ShopNest adds a DiscountCode column, you create a migration, review the SQL, then apply it on staging before production.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png