Beispiel #1
0
        private static void AddUserAccountWithDepartmentsInBatch()
        {
            NHibernateRepository <Department> dptRepository = new NHibernateRepository <Department>();

            dptRepository.Insert(new Department {
                DepartmentName = "Department 100"
            });
            dptRepository.Insert(new Department {
                DepartmentName = "Department 200"
            });
            dptRepository.Insert(new Department {
                DepartmentName = "Department 300"
            });
            dptRepository.Insert(new Department {
                DepartmentName = "Department 400"
            });
            dptRepository.Insert(new Department {
                DepartmentName = "Department 500"
            });
            dptRepository.Save();

            List <Department> dpts = dptRepository.All().ToList();

            NHibernateRepository <UserAccount> accountsRepository = new NHibernateRepository <UserAccount>();

            for (int i = 0; i < 5000; i++)
            {
                UserAccount acct = new UserAccount();
                acct.Email    = "mscsharp_" + i + "@gmail.com";
                acct.Password = i + "_password";
                acct.Username = "******" + i;

                Department rndDpt = dpts[new Random().Next(dpts.Count)];

                //if (i < 100)
                //    acct.Department = dpts.Find(x => x.DepartmentName.Contains("100"));
                //else if (i < 200)
                //    acct.Department = dpts.Find(x => x.DepartmentName.Contains("200"));

                //else if (i < 300)
                //    acct.Department = dpts.Find(x => x.DepartmentName.Contains("300"));

                //else if (i < 400)
                //    acct.Department = dpts.Find(x => x.DepartmentName.Contains("400"));

                //else if (i < 500)
                //    acct.Department = dpts.Find(x => x.DepartmentName.Contains("500"));

                acct.Department = rndDpt;


                accountsRepository.Insert(acct);
            }
            accountsRepository.Save();
        }
Beispiel #2
0
        private static void AddCitys()
        {
            NHibernateRepository <City> cityRepository = new NHibernateRepository <City>();
            City c = new City()
            {
                Name = "c1", Population = 2000000, Municipality = new Municipality
                {
                    Name = "M1"
                }
            };

            cityRepository.Insert(c);
            cityRepository.Save();
        }