public override void Generate() { var categoryNamesToBeAdded = new HashSet<string>(); Console.WriteLine("Adding categories"); while (categoryNamesToBeAdded.Count < this.count) { categoryNamesToBeAdded.Add(this.random.GetRandomStringRandomLength(5, 20)); } int index = 0; foreach (string categoryName in categoryNamesToBeAdded) { var category = new Category { Name = categoryName }; db.Categories.Add(category); index++; if (index % 100 == 0) { db.SaveChanges(); Console.Write("."); } } //db.SaveChanges(); Console.WriteLine("Categories added"); }
public Category GetRandomCategory() { var category = new Category() { Name = generator.GetRandomString(1, 40) }; return category; }
public override void Generate() { Console.WriteLine("Generating Categories"); for (int i = 0; i < this.Count; i++) { var newCategory = new Category { Name = this.Random.GetString(2, 50) }; Db.Categories.Add(newCategory); if (i % 100 == 0) { Console.Write("."); Db.SaveChanges(); } } Console.WriteLine("\nGenerating Categories Done!"); }