Exemple #1
0
 private static void RunAddAndSaveChangesTest()
 {
     Console.WriteLine("Add & SaveChanges");
     RunTest(
         () =>
         {
             using (var db = new EF6.AdventureWorksContext())
             {
                 for (int i = 0; i < 1000; i++)
                 {
                     db.ProductCategories.Add(new EF6.ProductCategory { Name = $"Test {Guid.NewGuid()}" });
                 }
                 db.SaveChanges();
             }
         },
         () =>
         {
             using (var db = new EFCore.AdventureWorksContext())
             {
                 for (int i = 0; i < 1000; i++)
                 {
                     db.ProductCategories.Add(new EFCore.ProductCategory { Name = $"Test {Guid.NewGuid()}" });
                 }
                 db.SaveChanges();
             }
         });
 }
Exemple #2
0
 private static void RunComplexQueryTest()
 {
     Console.WriteLine("Query Complex");
     RunTest(
         ef6Test: () =>
     {
         using (var db = new EF6.AdventureWorksContext())
         {
             db.Customers
             .Where(c => !c.AccountNumber.EndsWith("1"))
             .OrderBy(c => c.AccountNumber)
             .ThenBy(c => c.ModifiedDate)
             .Skip(100)
             .GroupBy(c => c.TerritoryID)
             .ToList();
         }
     },
         ef7Test: () =>
     {
         using (var db = new EFCore.AdventureWorksContext())
         {
             db.Customers
             .Where(c => !c.AccountNumber.EndsWith("1"))
             .OrderBy(c => c.AccountNumber)
             .ThenBy(c => c.ModifiedDate)
             .Skip(100)
             .GroupBy(c => c.TerritoryID)
             .ToList();
         }
     });
 }
Exemple #3
0
 private static void RunComplexQueryTest()
 {
     Console.WriteLine("Query Complex");
     RunTest(
         ef6Test: () =>
         {
             using (var db = new EF6.AdventureWorksContext())
             {
                 db.Customers
                     .Where(c => !c.AccountNumber.EndsWith("1"))
                     .OrderBy(c => c.AccountNumber)
                     .ThenBy(c => c.ModifiedDate)
                     .Skip(100)
                     .GroupBy(c => c.TerritoryID)
                     .ToList();
             }
         },
         ef7Test: () =>
         {
             using (var db = new EFCore.AdventureWorksContext())
             {
                 db.Customers
                     .Where(c => !c.AccountNumber.EndsWith("1"))
                     .OrderBy(c => c.AccountNumber)
                     .ThenBy(c => c.ModifiedDate)
                     .Skip(100)
                     .GroupBy(c => c.TerritoryID)
                     .ToList();
             }
         });
 }
Exemple #4
0
 private static void RunAddAndSaveChangesTest()
 {
     Console.WriteLine("Add & SaveChanges");
     RunTest(
         () =>
     {
         using (var db = new EF6.AdventureWorksContext())
         {
             for (int i = 0; i < 1000; i++)
             {
                 db.ProductCategories.Add(new EF6.ProductCategory {
                     Name = $"Test {Guid.NewGuid()}"
                 });
             }
             db.SaveChanges();
         }
     },
         () =>
     {
         using (var db = new EFCore.AdventureWorksContext())
         {
             for (int i = 0; i < 1000; i++)
             {
                 db.ProductCategories.Add(new EFCore.ProductCategory {
                     Name = $"Test {Guid.NewGuid()}"
                 });
             }
             db.SaveChanges();
         }
     });
 }
Exemple #5
0
 private static void RunAddAndSaveChangesOptimizedTest()
 {
     Console.WriteLine("Add & SaveChanges (EF6 Optimized)");
     RunTest(
         () =>
     {
         using (var db = new EF6.AdventureWorksContext())
         {
             db.Configuration.AutoDetectChangesEnabled = false;
             var categories = new EF6.ProductCategory[1000];
             for (int i = 0; i < 1000; i++)
             {
                 categories[i] = new EF6.ProductCategory {
                     Name = $"Test {Guid.NewGuid()}"
                 };
             }
             db.ProductCategories.AddRange(categories);
             db.SaveChanges();
         }
     },
         () =>
     {
         using (var db = new EFCore.AdventureWorksContext())
         {
             for (int i = 0; i < 1000; i++)
             {
                 db.ProductCategories.Add(new EFCore.ProductCategory {
                     Name = $"Test {Guid.NewGuid()}"
                 });
             }
             db.SaveChanges();
         }
     });
 }
Exemple #6
0
 private static void ResetAndWarmup()
 {
     using (var db = new EF6.AdventureWorksContext()) {
         db.Database.ExecuteSqlCommand(@"DELETE FROM Production.ProductCategory WHERE Name LIKE 'Test %'");
         db.Customers.FirstOrDefault();
     }
     using (var db = new EFCore.AdventureWorksContext()) {
         db.Customers.FirstOrDefault();
     }
 }
Exemple #7
0
        private static void ResetAndWarmup()
        {
            using (var db = new EF6.AdventureWorksContext())
            {
                db.Database.ExecuteSqlCommand(@"DELETE FROM Production.ProductCategory WHERE Name LIKE 'Test %'");
                db.Customers.FirstOrDefault();
            }

            using (var db = new EFCore.AdventureWorksContext())
            {
                db.Customers.FirstOrDefault();
            }
        }
Exemple #8
0
 private static void RunToListTest()
 {
     Console.WriteLine("Query ToList");
     RunTest(
         ef6Test: () => {
         using (var db = new EF6.AdventureWorksContext()) {
             db.Customers.ToList();
         }
     },
         ef7Test: () => {
         using (var db = new EFCore.AdventureWorksContext()) {
             db.Customers.ToList();
         }
     });
 }
Exemple #9
0
        static void Main(string[] args)
        {
            ResetAndWarmup();

            RunTest(
                ef6Test: () =>
            {
                using (var db = new EF6.AdventureWorksContext())
                {
                }
            },
                ef7Test: () =>
            {
                using (var db = new EFCore.AdventureWorksContext())
                {
                }
            });
        }
Exemple #10
0
 private static void RunToListTest()
 {
     Console.WriteLine("Query ToList");
     RunTest(
         ef6Test: () =>
         {
             using (var db = new EF6.AdventureWorksContext())
             {
                 db.Customers.ToList();
             }
         },
         ef7Test: () =>
         {
             using (var db = new EFCore.AdventureWorksContext())
             {
                 db.Customers.ToList();
             }
         });
 }
Exemple #11
0
        static void Main(string[] args)
        {
            ResetAndWarmup();

            RunTest(
                ef6Test: () =>
                {
                    using (var db = new EF6.AdventureWorksContext())
                    {
                        
                    }
                },
                efCoreTest: () =>
                {
                    using (var db = new EFCore.AdventureWorksContext())
                    {
                        
                    }
                });
        }
Exemple #12
0
 private static void RunAddAndSaveChangesOptimizedTest()
 {
     Console.WriteLine("Add & SaveChanges (EF6 Optimized)");
     RunTest(
         () =>
         {
             using (var db = new EF6.AdventureWorksContext())
             {
                 db.Configuration.AutoDetectChangesEnabled = false;
                 var categories = new EF6.ProductCategory[1000];
                 for (int i = 0; i < 1000; i++)
                 {
                     categories[i] = new EF6.ProductCategory { Name = $"Test {Guid.NewGuid()}" };
                 }
                 db.ProductCategories.AddRange(categories);
                 db.SaveChanges();
             }
         },
         () =>
         {
             using (var db = new EFCore.AdventureWorksContext())
             {
                 for (int i = 0; i < 1000; i++)
                 {
                     db.ProductCategories.Add(new EFCore.ProductCategory { Name = $"Test {Guid.NewGuid()}" });
                 }
                 db.SaveChanges();
             }
         });
 }