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."); }
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!"); }
private static void ResetDatabase() { var db = new PetStoreEntities(); db.Database.Delete(); db.Database.Create(); }
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!"); }
private static void AddRandomCountries(PetStoreEntities dbPets) { for (int counter = 0; counter < 20; counter++) { Country randomCountry = new Country(); randomCountry.Name = CustomRandomGenerator.GetRandomString(0, 49); dbPets.Countries.Add(randomCountry); } dbPets.SaveChanges(); Console.WriteLine("Random countries successfully added!"); }
private static void AddRandomCountries(PetStoreEntities dbPets) { for (int counter = 0; counter < 20; counter++) { Country randomCountry = new Country(); randomCountry.Name = CustomRandomGenerator.GetRandomString(0, 49); dbPets.Countries.Add(randomCountry); } dbPets.SaveChanges(); Console.WriteLine("Random countries successfully added!"); }
public static void Main() { cachedSpecies = new List<Species>(); PetStoreEntities dbPets = new PetStoreEntities(); using (dbPets) { //AddRandomCountries(dbPets); AddRandomSpecies(dbPets); //AddRandomPets(dbPets); //AddRandomCategories(dbPets); AddRandomProducts(dbPets); } }
public static void Main() { cachedSpecies = new List <Species>(); PetStoreEntities dbPets = new PetStoreEntities(); using (dbPets) { //AddRandomCountries(dbPets); AddRandomSpecies(dbPets); //AddRandomPets(dbPets); //AddRandomCategories(dbPets); AddRandomProducts(dbPets); } }
public static void Main() { using (var db = new PetStoreEntities()) { CountriesImporter.Import(db, 20); SpeciesImporter.Import(db, 100); PetsImporter.Import(db, 5000); } using (var db = new PetStoreEntities()) { CategoriesImporter.Import(db, 50); ProductsImporter.Import(db, 20000); } }
public static void Main() { var data = new PetStoreEntities(); CountriesImporter.GenerateCountries(data); SpeciesImporter.GenerateSpecies(data); PetsImporter.GeneratePets(data); CategoriesImporter.GenerateCategories(data); Console.WriteLine("Products generation is slow and may take a while depending on your hardware..."); Console.WriteLine("Set the GenerateProducts method's second parameter to a lower number if you wish!"); ProductsImporter.GenerateProducts(data, 200); }
private static void AddRandomSpecies(PetStoreEntities dbPets) { int randomCountryId = CustomRandomGenerator.GetRandomNumber(1, 20); for (int counter = 0; counter < 100; counter++) { Species randomSpecies = new Species(); randomSpecies.Name = CustomRandomGenerator.GetRandomString(5, 49); if (counter % 5 == 0) { randomCountryId = CustomRandomGenerator.GetRandomNumber(1, 20); } randomSpecies.OriginCountryId = randomCountryId; cachedSpecies.Add(randomSpecies); dbPets.Species.Add(randomSpecies); } dbPets.SaveChanges(); Console.WriteLine("Random species successfully added!"); }
private static void AddRandomSpecies(PetStoreEntities dbPets) { int randomCountryId = CustomRandomGenerator.GetRandomNumber(1, 20); for (int counter = 0; counter < 100; counter++) { Species randomSpecies = new Species(); randomSpecies.Name = CustomRandomGenerator.GetRandomString(5, 49); if (counter % 5 == 0) { randomCountryId = CustomRandomGenerator.GetRandomNumber(1, 20); } randomSpecies.OriginCountryId = randomCountryId; cachedSpecies.Add(randomSpecies); dbPets.Species.Add(randomSpecies); } dbPets.SaveChanges(); Console.WriteLine("Random species successfully added!"); }
public static void Main() { var db = new PetStoreEntities(); db.Database.Delete(); db.Database.Create(); db.Colors.Add(new Color() { Name = "black" }); db.Colors.Add(new Color() { Name = "white" }); db.Colors.Add(new Color() { Name = "red" }); db.Colors.Add(new Color() { Name = "mixed" }); // Add countries Console.Write("\nAdding countries"); for (int i = 0; i < 20; i++) { db.Countries.Add( new Country() { Name = RandomGenerator.RandomString(RandomGenerator.RandomInt(5, 50)), }); if (i % 250 == 0) { Console.Write("."); db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); } } db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); // Get all country ids var countryIds = db.Countries.Select(x => x.Id).ToList(); // add species Console.Write("\nAdding species"); for (int i = 0; i < 100; i++) { db.Species.Add( new Species() { Name = RandomGenerator.RandomString(RandomGenerator.RandomInt(5, 50)), CountryId = countryIds[RandomGenerator.RandomInt(0, countryIds.Count - 1)] }); if (i % 250 == 0) { Console.Write("."); db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); } } db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); // Get all needed ids var speciesIds = db.Species.Select(x => x.Id).ToList(); var colorIds = db.Colors.Select(x => x.Id).ToList(); // add pets Console.Write("\nAdding pets"); for (int i = 0; i < 5000; i++) { db.Pets.Add( new Pet() { SpeciesId = speciesIds[RandomGenerator.RandomInt(0, speciesIds.Count - 1)], Birthdate = RandomGenerator.RandomDate(DateTime.Now, DateTime.MaxValue), // todo ???? Price = RandomGenerator.RandomInt(500, 250000) / 100, ColorId = colorIds[RandomGenerator.RandomInt(0, colorIds.Count - 1)], Breed = RandomGenerator.RandomString(RandomGenerator.RandomInt(5, 30)), }); if (i % 250 == 0) { Console.Write("."); db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); } } db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); // add categories Console.Write("\nAdding categories"); for (int i = 0; i < 50; i++) { db.ProductCategories.Add( new ProductCategory() { Name = RandomGenerator.RandomString(RandomGenerator.RandomInt(5, 20)), }); if (i % 250 == 0) { Console.Write("."); db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); } } db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); // Get all needed ids var productCategoryIds = db.ProductCategories.Select(x => x.Id).ToList(); // add products Console.Write("\nAdding products"); for (int i = 0; i < 20000; i++) { db.Products.Add( new Product() { Name = RandomGenerator.RandomString(RandomGenerator.RandomInt(5, 25)), CatyegoryId = productCategoryIds[RandomGenerator.RandomInt(0, productCategoryIds.Count - 1)], Price = RandomGenerator.RandomInt(1000, 100000) / 100, }); if (i % 250 == 0) { Console.Write("."); db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); } } // Get all needed ids var productIds = db.Products.Select(x => x.Id).ToList(); var speciesId = db.Species.Select(x => x.Id).ToList(); Console.Write("\nAdding products in species"); //add products in species for (int i = 0; i < 2000; i++) { db.ProductSpecies.Add( new ProductSpecy() { ProductId = productIds[RandomGenerator.RandomInt(0, productIds.Count - 1)], SpeciesId = speciesId[RandomGenerator.RandomInt(0, speciesId.Count - 1)], }); if (i % 250 == 0) { Console.Write("."); db.SaveChanges(); db.Dispose(); db = new PetStoreEntities(); } } db.SaveChanges(); db.Dispose(); }
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."); }