Entity Framework 6 Refresher: Seed Data
“Seed Data” is data that is inserted into the database when migrations are run. Generally, this would be relatively static look-up data such as States
or OrderStatuses
. but it can be anything you want.
Using the example of Person
in the previous post, we can use the seed functionality to created some records. To do this, open Configuration.cs
in the Migrations
folder. There will be Seed
method.
As noted in the comments the ` DbSet
PersonId
, which is an identity column, can be ignored or set explicitly.
The seed method can be run via update-database
in the PMC even without a pending migraiton.
Leave a Comment