Пример #1
0
        private static void GenerateData()
        {
            const int COUNT = 5000;
            Random rand = new Random();

            List<User> users = new List<User>();
            List<Car> cars = new List<Car>();
            List<Employer> employers = new List<Employer>();
            List<Address> addresses = new List<Address>();

            for (int i = 1; i <= COUNT; i++)
            {
                var user = new User() { Id = i, Name = Faker.NameFaker.Name(), BirthDate = Faker.DateTimeFaker.BirthDay() };
                var employer = new Employer() { Id = i, Name = Faker.CompanyFaker.Name(), EmployeeCount = Faker.NumberFaker.Number(10, 150000), Sector = Faker.EnumFaker.SelectFrom<Sector>() };
                var address = new Address()
                {
                    Id = i,
                    Street = Faker.LocationFaker.Street(),
                    City = Faker.LocationFaker.City(),
                    State = Faker.LocationFaker.Country(),
                    PostalCode = Faker.LocationFaker.PostCode()
                };
                var car = new Car() { Id = i, MakeModel = Faker.EnumFaker.SelectFrom<MakeModel>(), Year = Faker.NumberFaker.Number(1990, 2016) };

                users.Add(user);
                cars.Add(car);
                employers.Add(employer);
                addresses.Add(address);
            }

            foreach (var employer in employers)
            {
                employer.Address = addresses[rand.Next(COUNT)];
            }

            foreach (var user in users)
            {
                for (int i = 0; i <= 5; i++)
                {
                    var index = rand.Next(COUNT);
                    if (!user.Cars.Contains(cars[index]))
                    {
                        user.Cars.Add(cars[index]);
                    }
                }
                user.Address = addresses[rand.Next(COUNT)];
                user.Employer = employers[rand.Next(COUNT)];
            }

            Save(users, cars, employers, addresses);
        }
Пример #2
0
 private static void SaveCar(Car car, SqlConnection connection)
 {
     var cmd = new SqlCommand($"INSERT INTO dbo.Car VALUES ({car.Id}, {(int)(car.MakeModel)}, {car.Year})", connection);
     cmd.ExecuteNonQuery();
 }