public static void Main(string[] args) { CurrentDirectoryHelpers.SetCurrentDirectory(); var host = CreateWebHostBuilder(args).Build(); #if !(DEBUG) Thread.Sleep(10000); // wait for start of postgres container (cannot understand how to add wait for it script) #endif using (var scope = host.Services.CreateScope()) { try { var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); context.Database.Migrate(); CoursesInitializer.Initialize(context); } catch (Exception ex) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while migrating or initializing the database."); } } host.Run(); }
protected override void Seed(Shop.DataAccessLayer.CoursesContext context) { CoursesInitializer.SeedCoursesData(context); // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. }
protected override void Seed(PraktyczneKursy.DAL.CoursesContext context) { //CoursesInitializer.SeedCoursesData(context); CoursesInitializer.SeedUsers(context); // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. }
public static ApplicationDbContext Create() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new ApplicationDbContext(options); context.Database.EnsureCreated(); CoursesInitializer.Initialize(context); return(context); }