© Eric Vogel 2021
E. VogelBeginning Entity Framework Core 5https://doi.org/10.1007/978-1-4842-6882-7_6

6. Seeding Data

Eric Vogel1  
(1)
Okemos, MI, USA
 

In the last chapter, we finally created our database using Entity Framework Core 5. In this chapter, we will seed our database with some data. We will add a few sample persons and addresses and load up our lookup tables with some states and countries.

Populating Lookup Data

We will start out by populating some lookup records for states and countries. To get started, open the AppDbContext class file. To seed data, we override the OnModelCreating method like this:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}

The OnModelCreating event can also be used to configure the database schema, ...

Get Beginning Entity Framework Core 5: From Novice to Professional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.