Example #1
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            PeopleDBContext context = app.ApplicationServices
                                      .CreateScope().ServiceProvider.GetRequiredService <PeopleDBContext>();

            if (context.Database.GetPendingMigrations().Any())
            {
                context.Database.Migrate();
            }
            if (!context.People.Any())
            {
                context.People.AddRange(
                    new Person
                {
                    Name       = "Alex",
                    FatherName = "Jose",
                    MotherName = "Claudia",
                    LastName   = "Sanchez"
                },
                    new Person
                {
                    Name       = "Jake",
                    FatherName = "Bill",
                    MotherName = "Hana",
                    LastName   = "Williams"
                },
                    new Person
                {
                    Name       = "Claudia",
                    FatherName = "Jim",
                    MotherName = "Jane",
                    LastName   = "George"
                },
                    new Person
                {
                    Name       = "Lucy",
                    FatherName = "Vincent",
                    MotherName = "Lucretia",
                    LastName   = "Valentine"
                }
                    );
                context.SaveChanges();
            }
        }
 public EFPeopleRepository(PeopleDBContext ctx)
 {
     context = ctx;
 }