Пример #1
0
        static void Main(string[] args)
        {
            var timer = new Stopwatch();

            int numberOfRabbitsToCreate = 1000;


            for (int i = 0; i < numberOfRabbitsToCreate; i++)
            {
                using (var db = new RabbitDbEntities())
                {
                    var newRabbit = new Rabbit();
                    db.Rabbits.Add(newRabbit);
                    db.SaveChanges();
                }
            }

            //timer.Stop();
            //Console.WriteLine("1 read took: " + timer.ElapsedMilliseconds);
            // one read
            timer.Start();

            using (var db = new RabbitDbEntities())
            {
                rabbits = db.Rabbits.ToList();
            }
            timer.Stop();

            Console.WriteLine("1 Read took: " + timer.ElapsedMilliseconds + "Milliseconds");


            timer.Restart();
            // 1000 reads
            for (int i = 0; i < numberOfRabbitsToCreate; i++)
            {
                using (var db = new RabbitDbEntities())
                {
                    Rabbit newRabbit = db.Rabbits.Find(i + 1);
                    //Rabbit newRabbit = db.Rabbits.ToList()[i];
                    rabbits.Add(newRabbit);
                }
            }
            timer.Stop();
            Console.WriteLine("1000 reads took: " + timer.ElapsedMilliseconds);


            // REPORT TIMES TO CONSOLE
            // REPORT TIMES TO CSV
            File.WriteAllText("Rabbits.csv", "ID,Name,Age");
            File.AppendAllText("Rabbits.csv", "\n1,Billy,12");
            File.AppendAllText("Rabbits.csv", "\n2,Fluffy,13");
            Process.Start("Rabbits.csv");
            Console.ReadKey();
            // REPORT TIMES TO WORD
            // SPRINT 2: move everything to WPF
        }
Пример #2
0
        static void AddBunnies()
        {
            var newRabbit = new Rabbit()
            {
                Age        = 0,
                RabbitName = $"Rabbit whatever"
            };

            using (var db = new RabbitDbEntities())
            {
                db.Rabbits.Add(newRabbit);
                db.SaveChanges();
            }
        }
Пример #3
0
        public void PopRabbitDb1(int numberOfRabbits)
        {
            Random rand = new Random();

            using (var db = new RabbitDbEntities())
            {
                for (int i = 0; i < numberOfRabbits; i++)
                {
                    Rabbit rb = new Rabbit();
                    rb.Age  = rand.Next(21);
                    rb.Name = $"Jeff{i}";
                    db.Rabbits.Add(rb);
                    db.SaveChanges();
                }
            }
        }