コード例 #1
0
        public static void ByAddWithNoDetect(int count)
        {
            DatabaseOps.ClearPrimaryTable();

            var entities = EntityGenerator.Generate(count);

            using (var context = new EntityDataModel())
            {
                var stopwatch = new Stopwatch();

                stopwatch.Start();

                context.Configuration.AutoDetectChangesEnabled = false;

                entities.ForEach(entity => context.Orders.Add(entity));

                context.Configuration.AutoDetectChangesEnabled = true;

                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("NoDetect({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }
コード例 #2
0
        public static void BySqlBulkCopy(int count, bool output = true)
        {
            DatabaseOps.ClearPrimaryTable();

            var entities = EntityGenerator.Generate(count);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            BulkCopy(entities, "Order");

            stopwatch.Stop();

            if (output)
            {
                Console.WriteLine("BulkCopy({0}) = {1} s", entities.Count, stopwatch.Elapsed.TotalSeconds);
            }
        }
コード例 #3
0
        public static void ByRange(int count)
        {
            DatabaseOps.ClearPrimaryTable();

            var entities = EntityGenerator.Generate(count);

            using (var context = new EntityDataModel())
            {
                var stopwatch = new Stopwatch();

                stopwatch.Start();

                context.Orders.AddRange(entities);
                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("Range({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }
コード例 #4
0
        public static void ByAdd(int count)
        {
            DatabaseOps.ClearPrimaryTable();

            //Создаем нужное количество объектов для добавления в контекст
            var entities = EntityGenerator.Generate(count);

            using (var context = new EntityDataModel())
            {
                var stopwatch = new Stopwatch();

                stopwatch.Start();

                entities.ForEach(entity => context.Orders.Add(entity));

                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("Add({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }