Creating a DbSeeder class

Let’s start by adding a DbSeeder.cs static class to the /Data/ folder. This class will use the ApplicationDbContext to create some sample entities and save them to our Database; doing that will take a considerable amount of code, hence it might be useful to split the various class components into #region blocks so that we can better understand the various steps.

Let's start with the Public Methods region, which will contain the methods that we want to make available from external classes:

[...]#region Public Methodspublic static void Seed(ApplicationDbContext dbContext){    // Create default Users (if there are none)    if (!dbContext.Users.Any()) CreateUsers(dbContext); // Create default Quizzes (if there are none) together ...

Get ASP.NET Core 2 and Angular 5 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.