コード例 #1
0
        private static void AddRandomPets(PetStoreEntities dbPets)
        {
            int randomSpeciesId = CustomRandomGenerator.GetRandomNumber(13, 112);

            for (int counter = 0; counter < 5000; counter++)
            {
                Pet randomPet = new Pet();

                if (counter % 50 == 0)
                {
                    randomSpeciesId = CustomRandomGenerator.GetRandomNumber(13, 112);
                }

                randomPet.SpeciesId = randomSpeciesId;

                randomPet.BirthDate = CustomRandomGenerator.GetRandomDate();

                randomPet.Price = (decimal)CustomRandomGenerator.GetRandomDouble();

                randomPet.ColorId = CustomRandomGenerator.GetRandomNumber(1, 4);

                dbPets.Pets.Add(randomPet);

                if (counter % 500 == 0)
                {
                    dbPets.SaveChanges();
                }
            }

            dbPets.SaveChanges();
            Console.WriteLine("Random pets successfully added!");
        }
コード例 #2
0
        private static void AddRandomProducts(PetStoreEntities dbPets)
        {
            int randomCategoryId = CustomRandomGenerator.GetRandomNumber(1, 50);

            for (int counter = 0; counter < 20000; counter++)
            {
                Product randomProduct = new Product();

                randomProduct.Name  = CustomRandomGenerator.GetRandomString(5, 25);
                randomProduct.Price = (decimal)CustomRandomGenerator.GetRandomDouble(10.0d, 10000.0d);

                if (counter % 400 == 0)
                {
                    randomCategoryId = CustomRandomGenerator.GetRandomNumber(1, 50);
                }

                randomProduct.CategoryId = randomCategoryId;

                for (int i = 0; i < 2; i++)
                {
                    int randomSpeciesPositionFromCache = CustomRandomGenerator.GetRandomNumber(0, 99);
                    randomProduct.Species.Add(cachedSpecies[randomSpeciesPositionFromCache]);
                }

                dbPets.Products.Add(randomProduct);

                if (counter % 500 == 0)
                {
                    dbPets.SaveChanges();
                }
            }

            dbPets.SaveChanges();
            Console.WriteLine("Random products successfully added.");
        }