public static async Task InitializePartsUnlimitedDatabaseAsync()

in Hands-on lab/lab-files/src/src/PartsUnlimitedWebsite/Models/SampleData.cs [26:42]


        public static async Task InitializePartsUnlimitedDatabaseAsync(IServiceProvider serviceProvider, bool createUser = true)
        {
            using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
            {
                var db = serviceScope.ServiceProvider.GetService<PartsUnlimitedContext>();

                //Seeding a database using migrations is not yet supported. (https://github.com/aspnet/EntityFramework/issues/629)
                //Add seed data, only if the tables are empty.
                bool tablesEmpty = !db.Products.Any() && !db.Orders.Any() && !db.Categories.Any() && !db.Stores.Any();

                if (tablesEmpty)
                {
                    await InsertTestData(serviceProvider);
                    //await CreateAdminUser(serviceProvider);
                }
            }
        }