Skip to content

10 Start Database with Sample Data (Database Seed)

M. Fares edited this page Apr 22, 2018 · 2 revisions

You may start your database with sample data such as the list of departments, categories of products, types of emplyees etc.

To seed your database, insert data in /Migrations/Configurations.cs/Seed() methods.

Seeding the users and roles has to be done through the usermanager and role manager (see admin example).

The method AddOrUpdate() is used in case the data already exists, so it will be updated.

AddOrUpdate method rules:

  • The property should not be a primary key with identity
  • The values of the property should be unique

Clone this wiki locally