예제 #1
0
        private static long BenchmarkInsert(int count,
            Action<EntityDataContext> contextAction)
        {
            var sw = new Stopwatch();
            sw.Start();

            for (int i = 0; i < count; i++)
            {
                using (var dataContext = new EntityDataContext())
                {
                    dataContext.Configuration.AutoDetectChangesEnabled = false;

                    contextAction(dataContext);

                    dataContext.SaveChanges();
                }
            }

            sw.Stop();
            return sw.ElapsedMilliseconds;
        }
예제 #2
0
        private static void PopulateTablesForSelects(int count)
        {
            Console.WriteLine("Populating tables for select benchmark with {0} records", count);

            for (int i = 0; i < count; i++)
            {
                using (var dc = new EntityDataContext())
                {
                    var p1 = new GuidKeySequentialParentEntity
                    {
                        Name = "Entity" + i,
                        Children1 = new List<GuidKeySequentialChildEntity1>(),
                        Children2 = new List<GuidKeySequentialChildEntity2>(),
                        Children3 = new List<GuidKeySequentialChildEntity3>(),
                        Children4 = new List<GuidKeySequentialChildEntity4>(),
                        Children5 = new List<GuidKeySequentialChildEntity5>()
                    };
                    var p2 = new GuidKeyNonSequentialParentEntity
                    {
                        Name = "Entity" + i,
                        Children1 = new List<GuidKeyNonSequentialChildEntity1>(),
                        Children2 = new List<GuidKeyNonSequentialChildEntity2>(),
                        Children3 = new List<GuidKeyNonSequentialChildEntity3>(),
                        Children4 = new List<GuidKeyNonSequentialChildEntity4>(),
                        Children5 = new List<GuidKeyNonSequentialChildEntity5>()
                    };
                    var p3 = new AutoIncrementIntKeyParentEntity
                    {
                        Name = "Entity" + i,
                        Children1 = new List<AutoIncrementIntKeyChildEntity1>(),
                        Children2 = new List<AutoIncrementIntKeyChildEntity2>(),
                        Children3 = new List<AutoIncrementIntKeyChildEntity3>(),
                        Children4 = new List<AutoIncrementIntKeyChildEntity4>(),
                        Children5 = new List<AutoIncrementIntKeyChildEntity5>()
                    };

                    for (int j = 0; j < 10; j++)
                    {
                        var c11 = new GuidKeySequentialChildEntity1
                        {
                            Name = "Child1" + i + "_" + j
                        };
                        var c12 = new GuidKeySequentialChildEntity2
                        {
                            Name = "Child2" + i + "_" + j
                        };
                        var c13 = new GuidKeySequentialChildEntity3
                        {
                            Name = "Child3" + i + "_" + j
                        };
                        var c14 = new GuidKeySequentialChildEntity4
                        {
                            Name = "Child4" + i + "_" + j
                        };
                        var c15 = new GuidKeySequentialChildEntity5
                        {
                            Name = "Child5" + i + "_" + j
                        };

                        var c21 = new GuidKeyNonSequentialChildEntity1
                        {
                            Name = "Child1" + i + "_" + j
                        };
                        var c22 = new GuidKeyNonSequentialChildEntity2
                        {
                            Name = "Child2" + i + "_" + j
                        };
                        var c23 = new GuidKeyNonSequentialChildEntity3
                        {
                            Name = "Child3" + i + "_" + j
                        };
                        var c24 = new GuidKeyNonSequentialChildEntity4
                        {
                            Name = "Child4" + i + "_" + j
                        };
                        var c25 = new GuidKeyNonSequentialChildEntity5
                        {
                            Name = "Child5" + i + "_" + j
                        };

                        var c31 = new AutoIncrementIntKeyChildEntity1
                        {
                            Name = "Child1" + i + "_" + j
                        };
                        var c32 = new AutoIncrementIntKeyChildEntity2
                        {
                            Name = "Child2" + i + "_" + j
                        };
                        var c33 = new AutoIncrementIntKeyChildEntity3
                        {
                            Name = "Child3" + i + "_" + j
                        };
                        var c34 = new AutoIncrementIntKeyChildEntity4
                        {
                            Name = "Child4" + i + "_" + j
                        };
                        var c35 = new AutoIncrementIntKeyChildEntity5
                        {
                            Name = "Child5" + i + "_" + j
                        };

                        p1.Children1.Add(c11);
                        p1.Children2.Add(c12);
                        p1.Children3.Add(c13);
                        p1.Children4.Add(c14);
                        p1.Children5.Add(c15);

                        p2.Children1.Add(c21);
                        p2.Children2.Add(c22);
                        p2.Children3.Add(c23);
                        p2.Children4.Add(c24);
                        p2.Children5.Add(c25);

                        p3.Children1.Add(c31);
                        p3.Children2.Add(c32);
                        p3.Children3.Add(c33);
                        p3.Children4.Add(c34);
                        p3.Children5.Add(c35);
                    }

                    dc.GuidKeySequentialParentEntities.Add(p1);
                    dc.GuidKeyNonSequentialParentEntities.Add(p2);
                    dc.AutoIncrementIntKeyParentEntities.Add(p3);
                    dc.SaveChanges();
                }
            }
        }