public static void ByMerge(int count)
        {
            DatabaseOps.ClearPrimaryTable();
            DatabaseOps.CreateTempTable();

            Insert.BySqlBulkCopy(count, false);

            using (var context = new EntityDataModel())
            {
                var entities = context.Orders.ToList();

                entities.ForEach(entity => entity.Date = DateTime.Now.AddYears(100));

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                Insert.BulkCopy(entities, "Order_TEMP");

                DatabaseOps.Merge();

                stopwatch.Stop();

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

            DatabaseOps.DropTempTable();
        }
        public static void BySaveChanges(int count)
        {
            DatabaseOps.ClearPrimaryTable();
            Insert.BySqlBulkCopy(count, false);

            using (var context = new EntityDataModel())
            {
                var entities = context.Orders.ToList();

                entities.ForEach(entity => entity.Date = DateTime.Now.AddYears(666));

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("SaveChanges({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            //int[] entityCounts = {1000, 10000, 100000};
            int[] entityCounts = { 100 };

            Console.WriteLine("Insert comparison:");
            Console.WriteLine();

            foreach (int count in entityCounts)
            {
                Console.WriteLine("Inserting {0} records...", count);

                Insert.ByAdd(count);
                Insert.ByAddWithNoDetect(count);
                Insert.ByRecreateContext(count);
                Insert.ByRange(count);
                Insert.BySqlBulkCopy(count);

                Console.WriteLine();
            }

            Console.WriteLine("Update comparison:");
            Console.WriteLine();

            foreach (int count in entityCounts)
            {
                Console.WriteLine("Updating {0} records...", count);

                Update.BySaveChanges(count);
                Update.ByMerge(count);

                Console.WriteLine();
            }

            Console.WriteLine("All tests done!");
            Console.ReadLine();
        }