private static void Migrate(BlazorDbContext context) { if (context.Database.GetPendingMigrations().Any()) { context.Database.Migrate(); } }
private static void SeedProducts(BlazorDbContext context) { if (!context.Products.Any()) { AddInitialProducts(context); context.SaveChanges(); } }
private static void SeedCategories(BlazorDbContext context) { if (!context.Categories.Any()) { AddInitialCategories(context); context.SaveChanges(); } }
private static void SeedRateRanges(BlazorDbContext context) { if (!context.RateRanges.Any()) { AddInitialRateRanges(context); context.SaveChanges(); } }
public static void SeedDatabase(this IApplicationBuilder app) { BlazorDbContext context = app.ApplicationServices .CreateScope() .ServiceProvider .GetRequiredService <BlazorDbContext>(); Migrate(context); SeedRateRanges(context); SeedCategories(context); SeedProducts(context); }
private static void AddInitialProducts(BlazorDbContext context) { context.Products.AddRange( InitialData.Products ); }
private static void AddInitialCategories(BlazorDbContext context) { context.Categories.AddRange( InitialData.Categories ); }
private static void AddInitialRateRanges(BlazorDbContext context) { context.RateRanges.AddRange( InitialData.RateRanges ); }