Esempio n. 1
0
        protected async override void OnStartup(StartupEventArgs e)
        {
            IServiceProvider provider = CreateServiceProvider();

            try
            {
                ApplicationDbContext context = provider.GetRequiredService <ApplicationDbContext>();

                if (context.Database.IsSqlServer())
                {
                    context.Database.Migrate();
                }

                await ApplicationDbContextSeed.SeedDefaultData(context);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"An error occurred while migrating or seeding the database.\n{ex.Message}", "Error");
                throw;
            }

            MainWindow window = new MainWindow();

            window.DataContext = provider.GetRequiredService <MainWindowViewModel>();
            window.Show();

            base.OnStartup(e);
        }