Exemplo n.º 1
0
        static void Ef6WithBulk()
        {
            var fixture = new Fixture();

            var item = fixture.CreateMany <Product>(10000);

            Stopwatch stopwatch = new Stopwatch();

            Console.WriteLine("Iniciando comparación");
            Console.WriteLine("==ENTITY FRAMEWORK 6 WITH BULK==");
            Console.WriteLine("Insertando {0} registros", item.Count());

            using (var transactionScope = new TransactionScope())
            {
                var ctx = new CatalogEntities();

                stopwatch.Start();
                ctx.BulkInsert(item);
                ctx.SaveChanges();
                stopwatch.Stop();

                Console.WriteLine("Duracion {0} ms ", stopwatch.ElapsedMilliseconds);
                Console.WriteLine("Duracion {0} se ", stopwatch.Elapsed.Seconds);
                Console.WriteLine("Duracion {0} mi ", stopwatch.Elapsed.Minutes);
                stopwatch.Reset();

                Console.WriteLine("Obteniendo TODO los registros");
                stopwatch.Start();
                var reponse = ctx.Product;
                stopwatch.Stop();
                Console.WriteLine("Se obtuvo {0} en una duracion de {1} ms", reponse.Count(), stopwatch.ElapsedMilliseconds);
                Console.WriteLine("Se obtuvo {0} en una duracion de {1} se", reponse.Count(), stopwatch.Elapsed.Seconds);
                Console.WriteLine("Se obtuvo {0} en una duracion de {1} mi", reponse.Count(), stopwatch.Elapsed.Minutes);
            }
        }