예제 #1
0
        private static void CompareSimpleQuery()
        {
            Stopwatch watch = new Stopwatch();

            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine($" Iteration {i}");

                // With EF 6
                watch.Restart();
                using (var context = new EF6.StarWarsContext())
                {
                    context.People.ToList();
                }
                watch.Stop();
                var prevResult = watch.ElapsedMilliseconds;
                Console.WriteLine($"  - EF6.x:      {watch.ElapsedMilliseconds}ms");

                // With EF Core
                watch.Restart();
                using (var context = new EFCore.StarWarsContext(_options))
                {
                    context.People.ToList();
                }
                watch.Stop();
                Console.WriteLine($"  - EF Core:    {watch.ElapsedMilliseconds}ms");

                // Bottom line
                var improvement = (prevResult - watch.ElapsedMilliseconds) / (double)prevResult;
                Console.WriteLine($"  - Improvement:{improvement.ToString("P0")}");
                Console.WriteLine();
            }
        }
예제 #2
0
        public static void Warmup(bool clearData, DbContextOptions <EFCore.StarWarsContext> options)
        {
            using (var context = new StarWarsContext(options))
            {
                context.Database.EnsureCreated();
                context.People.FirstOrDefault();

                if (clearData && context.People.Any())
                {
                    context.Database.ExecuteSqlCommand("delete dbo.Starships");
                    context.Database.ExecuteSqlCommand("delete dbo.People");
                }
            }
        }
예제 #3
0
 internal static void LoadLotsOfData(DbContextOptions <EFCore.StarWarsContext> options)
 {
     using (var context = new StarWarsContext(options))
     {
         for (int i = 1; i < Program.TABLE_SIZE; i++)
         {
             context.People.Add(
                 new Person
             {
                 Name = $"Person #{i}",
             });
         }
         context.SaveChanges();
     }
 }