Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            IWebHost host = CreateWebHostBuilder(args).Build();

            IHostingEnvironment env = host.Services.GetService <IHostingEnvironment>();

            using (IServiceScope scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    Test_taskDbContext Test_taskDbContext = services.GetRequiredService <Test_taskDbContext>();
                    Test_taskDbContext.Database.EnsureCreated();
                    DataDbInitializer.Seed(Test_taskDbContext);
                }
                catch (Exception ex)
                {
                    ILogger <Program> logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();

            CreateWebHostBuilder(args).Build().Run();
        }
Ejemplo n.º 2
0
 public UnitOfWork(Test_taskDbContext dbContext)
 {
     this.dbContext        = dbContext;
     repositories          = new Dictionary <Type, object>();
     createdRepositoryLock = new object();
     transactionClosed     = true;
     transaction           = null;
 }
Ejemplo n.º 3
0
        public static void Seed(Test_taskDbContext context)
        {
            if (!context.Categories.Any())
            {
                context.Categories.AddRange(categories);
            }

            context.SaveChanges();
        }