示例#1
0
        protected override void Seed(Contexts.ToolContext 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.
            DepartmentInitializer.Initialize(context);
            RoleInitializer.Initialize(context);
            StockInitializer.Initialize(context);
            AdminInitializer.Initialize(context);
            StockKeeperInitializer.Initialize(context);
            context.SaveChanges();
        }
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <EmployeeContext>();
                    // context.Database.EnsureCreated();
                    DepartmentInitializer.Initialize(context);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured creating the DB");
                    // throw ex;
                }
            }

            host.Run();
        }