Esempio n. 1
0
        private static void BulkInsert(SQLiteDbContext db)
        {
            Stopwatch sw        = new Stopwatch();
            var       user      = db.Query <User>(x => x.Id > 0).Take(1).FirstOrDefault();
            var       dataTable = db.SqlQueryDataTable("select Name,Gender,Age,OpTime from Users LIMIT 1");

            DataTable dtNew = dataTable.Copy();

            dtNew.Clear();  //清楚数据

            for (var i = 0; i < 100000; i++)
            {
                dtNew.Rows.Add(dataTable.Rows[0].ItemArray);  //添加数据行
            }
            sw.Reset();
            sw.Start();
            db.BulkInsert("Users", dtNew);
            sw.Stop();
            Console.WriteLine("BulkInsert DataTable 耗时:" + sw.ElapsedMilliseconds);

            //var user = db.Query<User>(x => x.Id > 0).Take(1).FirstOrDefault();

            var newList = new List <User>();

            for (var i = 0; i < 100000; i++)
            {
                newList.Add(user);
            }
            sw.Reset();
            sw.Start();
            db.BulkInsert <User>("Users", newList);
            sw.Stop();
            Console.WriteLine("BulkInsert List 耗时:" + sw.ElapsedMilliseconds);
        }