示例#1
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                try
                {
                    var context = scope.ServiceProvider.GetService <EBookStoreDbContext>();
                    context.Database.Migrate();

                    EBookStoreDbInitializer.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();
        }
 public static void Create(EBookStoreDbContext context)
 {
     context.Database.EnsureCreated();
     EBookStoreDbInitializer.Initialize(context);
 }