public EFStoreRepository(StoreDbContext ctx)
 {
     context = ctx;
 }
Esempio n. 2
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            StoreDbContext context = app.ApplicationServices
                                     .CreateScope().ServiceProvider.GetRequiredService <StoreDbContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }
            if (!context.Employees.Any())
            {
                context.Employees.AddRange(
                    new Employee
                {
                    Name      = "Ninh",
                    Gender    = "Female",
                    Birthday  = new DateTime(2000, 10, 27),
                    Telephone = 0987654321,
                    Email     = "*****@*****.**",
                    Address   = "Bac Ninh"
                },
                    new Employee
                {
                    Name      = "Kayak",
                    Gender    = "Female",
                    Birthday  = new DateTime(2000, 11, 20),
                    Telephone = 0987654321,
                    Email     = "*****@*****.**",
                    Address   = "Ha Noi"
                },
                    new Employee
                {
                    Name      = "Lifejacket",
                    Gender    = "Male",
                    Birthday  = new DateTime(2000, 10, 27),
                    Telephone = 0987654321,
                    Email     = "*****@*****.**",
                    Address   = "Hai Phong"
                },
                    new Employee
                {
                    Name      = "Ball",
                    Gender    = "Male",
                    Birthday  = new DateTime(1999, 9, 20),
                    Telephone = 0987654321,
                    Email     = "*****@*****.**",
                    Address   = "Bac Ninh"
                },
                    new Employee
                {
                    Name      = "Jenny",
                    Gender    = "Female",
                    Birthday  = new DateTime(1998, 11, 2),
                    Telephone = 0987654321,
                    Email     = "*****@*****.**",
                    Address   = "Ha Noi"
                }

                    );
                context.SaveChanges();
            }
        }