Esempio n. 1
0
        public static void ImportCategories(int count)
        {
            Console.WriteLine("ImportCategories");
            var categoriesNames = new HashSet<string>();

            do
            {
                categoriesNames.Add(RandomGenerator.RandomString(5, 20));
            }
            while (categoriesNames.Count < count);

            var data = new PetStoreEntities();
            var counter = 0;
            foreach (var category in categoriesNames)
            {
                var newcategory = new Category()
                {
                    Name = category
                };

                data.Categories.Add(newcategory);
                counter++;

                if (counter % 100 == 0)
                {
                    data.SaveChanges();
                    data.Dispose();
                    data = new PetStoreEntities();
                    Console.Write(".");
                }
            }

            data.SaveChanges();
            data.Dispose();
        }
        public override void Execute()
        {
            this.Data = new PetStoreEntities();

            var names = this.GenerateSomeRandomeStrings(5, 20, MaxNumberOfCommands).ToList();

            for (int i = 0; i < MaxNumberOfCommands; i++)
            {
                var category = new Category()
                {
                    Name = names[i]
                };

                this.Data.Categories.Add(category);

                if (i % 10 == 0)
                {
                    Console.Write(".");
                }
            }

            this.Data.SaveChanges();
        }