示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();
            //只有.net 4.5 才行
            var options = new BulkInsertOptions
            {
                EnableStreaming = true,
            };
            List <tb> entities = new List <tb>();

            for (int i = 0; i < 50000; i++)
            {
                tb entity = new tb();
                entity.name     = "60000" + i;
                entity.password = "******" + entity.name;
                entities.Add(entity);
            }
            using (var db = new PermissionEntities())
            {
                db.BulkInsert(entities, options);
            } watch.Stop();
            MessageBox.Show("插入成功:耗时:" + watch.ElapsedMilliseconds);
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();
            List <tb> entities = new List <tb>();

            using (var db = new PermissionEntities())
            {
                using (var transactionScope = new TransactionScope())
                {
                    // some stuff in dbcontext
                    for (int i = 0; i < 20000; i++)
                    {
                        tb entity = new tb();
                        entity.name     = "40000" + i;
                        entity.password = "******" + entity.name;
                        entities.Add(entity);
                    }
                    db.BulkInsert(entities);

                    //db.SaveChanges();
                    transactionScope.Complete();
                }
            } watch.Stop();
            MessageBox.Show("插入成功:耗时:" + watch.ElapsedMilliseconds);
        }
示例#3
0
 private void button7_Click(object sender, EventArgs e)
 {
     //EF一定要有主键,否则报错
     using (var enty = new PermissionEntities())
     {
         tb aa = new tb();
         aa.name     = "10000";
         aa.password = "******" + aa.name;
         enty.tb.Add(aa);
         enty.tb.Attach(aa);
         enty.SaveChanges();
     }
 }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            //EF一定要有主键,否则报错
            using (var enty = new PermissionEntities())
            {
                for (int i = 0; i < 200; i++)
                {
                    tb aa = new tb();
                    aa.name     = (200 + i).ToString();
                    aa.password = "******" + aa.name;
                    enty.tb.Add(aa);
                }
                enty.SaveChanges();
            }

            MessageBox.Show("成功");
        }
示例#5
0
        private void button5_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();
            List <tb> tbs = new List <tb>();

            for (int i = 0; i < 10000; i++)
            {
                tb entity = new tb();
                entity.name     = "10000" + i;
                entity.password = "******" + entity.name;
                tbs.Add(entity);
            }
            using (var db = new PermissionEntities())
            {
                db.BulkInsert(tbs);
            }
            watch.Stop();
            MessageBox.Show("插入成功:耗时:" + watch.ElapsedMilliseconds);
        }