示例#1
0
        public double TestInsert()
        {
            using (var db = new AdoDatabaseContext(@"Server=DECAIREPC;Database=sampledata;Trusted_Connection=True;"))
            {
                // read first and last names
                var firstnames = new List <string>();
                using (var sr = new StreamReader(@"..\..\Data\firstnames.txt"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        firstnames.Add(line);
                    }
                }

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

                //test inserting 10000 records (only ~1,000 names in text)
                var startTime = DateTime.Now;
                for (int j = 0; j < 10; j++)
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        db.Add("@first", firstnames[i], SqlDbType.VarChar);
                        db.Add("@last", lastnames[i], SqlDbType.VarChar);
                        db.Add("@department", _departmentKey, SqlDbType.Int);

                        db.Execute("INSERT INTO Person (first,last,department) VALUES (@first,@last,@department)");
                    }
                }
                var elapsedTime = DateTime.Now - startTime;

                return(elapsedTime.TotalSeconds);
            }
        }
示例#2
0
        public double TestUpdate()
        {
            using (var db = new AdoDatabaseContext(@"Server=DECAIREPC;Database=sampledata;Trusted_Connection=True;"))
            {
                using (var dbwrite = new AdoDatabaseContext(@"Server=DECAIREPC;Database=sampledata;Trusted_Connection=True;"))
                {
                    // update all records in the person table
                    var startTime = DateTime.Now;
                    using (var result = db.ReadQuery("SELECT * FROM Person"))
                    {
                        while (result.Read())
                        {
                            dbwrite.Add("@last", result.GetFieldNullOrString("last") + "2", SqlDbType.VarChar);
                            dbwrite.Add("@id", result.GetFieldNullOrString("id"), SqlDbType.VarChar);
                            dbwrite.Execute("UPDATE Person SET last=@last WHERE id=@id");
                        }
                    }

                    var elapsedTime = DateTime.Now - startTime;

                    return(elapsedTime.TotalSeconds);
                }
            }
        }
示例#3
0
        public void InitializeData()
        {
            using (var db = new AdoDatabaseContext(@"Server=DECAIREPC;Database=sampledata;Trusted_Connection=True;"))
            {
                // delete any records from previous run
                db.Execute("DELETE FROM Person");

                db.Execute("DELETE FROM Department");

                // insert one department
                db.Add("@name", "Operations", SqlDbType.VarChar);

                db.Execute("INSERT INTO Department (name) VALUES (@name)");

                // select the primary key of the department table for the only record that exists
                using (var result = db.ReadQuery("SELECT d.id FROM Department d where d.name='Operations'"))
                {
                    while (result.Read())
                    {
                        _departmentKey = int.Parse(result.GetFieldNullOrString("id"));
                    }
                }
            }
        }