public void TestDelete()
        {
            using (var db = new SampleDataContext())
            {
                DateTime startTime = DateTime.Now;
                var personQuery = (from pers in db.Persons select pers).ToList();

                db.Persons.RemoveRange(personQuery);
                db.SaveChanges();
                TimeSpan elapsedTime = DateTime.Now - startTime;

                Console.WriteLine("DELETE:" + elapsedTime.ToString());
            }
        }
        public EFPerformanceTests()
        {
            // clean up any data from previous runs
            using (var db = new SampleDataContext())
            {
                // delete any records from previous run
                var deptQuery = (from dept in db.Departments select dept).ToList();
                db.Departments.RemoveRange(deptQuery);
                db.SaveChanges();

                var personQuery = (from pers in db.Persons select pers).ToList();
                db.Persons.RemoveRange(personQuery);
                db.SaveChanges();

                // insert one department
                Department myDepartment = new Department()
                {
                    name = "Operations"
                };

                db.Departments.Add(myDepartment);
                db.SaveChanges();
            }
        }
        public void TestInsert()
        {
            using (var db = new SampleDataContext())
            {
                // read first and last names
                List<string> firstnames = new List<string>();
                using (StreamReader sr = new StreamReader(@"..\..\Data\firstnames.txt"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                        firstnames.Add(line);
                }

                List<string> lastnames = new List<string>();
                using (StreamReader sr = new StreamReader(@"..\..\Data\lastnames.txt"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                        lastnames.Add(line);
                }

                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled = false;

                //test inserting 1000 records
                DateTime startTime = DateTime.Now;
                for (int j = 0; j < 10; j++)
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        Person personRecord = new Person()
                        {
                            first = firstnames[i],
                            last = lastnames[i],
                            department = 1
                        };

                        db.Persons.Add(personRecord);
                    }
                }

                db.SaveChanges();
                TimeSpan elapsedTime = DateTime.Now - startTime;

                Console.WriteLine("INSERT:" + elapsedTime.ToString());
            }
        }
        public void TestUpdate()
        {
            using (var db = new SampleDataContext())
            {
                DateTime startTime = DateTime.Now;
                var query = (from p in db.Persons select p).ToList();
                foreach (var item in query)
                {
                    item.last = item.last + "2";
                }
                db.SaveChanges();

                TimeSpan elapsedTime = DateTime.Now - startTime;

                Console.WriteLine("SELECT:" + elapsedTime.ToString());
            }
        }