public Linq2SqlPerformanceTests()
        {
            using (var db = new DataClasses1DataContext())
            {
                // delete any records from previous run
                var deptQuery = (from dept in db.Departments select dept).ToList();
                foreach (var item in deptQuery)
                {
                    db.Departments.DeleteOnSubmit(item);
                }
                db.SubmitChanges();

                var personQuery = (from pers in db.Persons select pers).ToList();
                foreach (var item in personQuery)
                {
                    db.Persons.DeleteOnSubmit(item);
                }
                db.SubmitChanges();

                Department myDepartment = new Department()
                {
                    name = "Operations"
                };

                db.Departments.InsertOnSubmit(myDepartment);
                db.SubmitChanges();
            }
        }
        public void TestDelete()
        {
            using (var db = new DataClasses1DataContext())
            {
                // delete all records in the person table
                DateTime startTime = DateTime.Now;
                var personQuery = (from pers in db.Persons select pers).ToList();
                foreach (var item in personQuery)
                {
                    db.Persons.DeleteOnSubmit(item);
                }
                db.SubmitChanges();
                TimeSpan elapsedTime = DateTime.Now - startTime;

                Console.WriteLine("DELETE:" + elapsedTime.ToString());
            }
        }
        public void TestUpdate()
        {
            using (var db = new DataClasses1DataContext())
            {
                // update all records in the person table
                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.SubmitChanges();
                TimeSpan elapsedTime = DateTime.Now - startTime;

                Console.WriteLine("UPDATE:" + elapsedTime.ToString());
            }
        }
        public void TestInsert()
        {
            using (var db = new DataClasses1DataContext())
            {
                // 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);
                }

                //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.InsertOnSubmit(personRecord);
                    }
                }

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

                Console.WriteLine("INSERT:" + elapsedTime.ToString());
                //3.49 seconds
            }
        }