예제 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            //在上面的方法中 会调用自动检测功能。  这个功能默认是开启的  当我们在做批量操作时 可以关闭这个来提高性能 .例如
            //List<tb> tbs = new List<tb>();
            //using (var context = new PermissionEntities())
            //{
            //    try
            //    {
            //        context.Configuration.AutoDetectChangesEnabled = false;

            //        foreach (var unicorn in tbs)
            //        {
            //            context.tb.Add(unicorn);
            //        }
            //        //  context.tb.AddRange(tbs);
            //    }
            //    finally
            //    {
            //        context.Configuration.AutoDetectChangesEnabled = true;
            //    }
            //}

            using (var db = new PermissionEntities())
            {
                string name = dataGridView1.CurrentRow.Cells[0].Value.ToString();

                var tbs = db.tb.Where(t => t.name == name).FirstOrDefault();
                db.tb.Remove(tbs);
                //db.Entry(tbs).State = EntityState.Deleted;
                db.SaveChanges();
            }
        }
예제 #2
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);
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();
            using (var db = new PermissionEntities())
            {
                //看看EF EL怎么解决
                // 复用的查询
                // base query
                var q = db.tb.Where(t => true);
                // get total count
                var q1 = q.FutureCount();
                // get page
                var q2 = q.OrderBy(t => t.name).Skip((int.Parse(textBox1.Text.Trim()) - 1) * 1000).Take(1000).Future();
                // triggers execute as a batch
                int total = q1.Value;
                var tasks = q2.ToList();

                label1.Text = total.ToString();
                dataGridView1.DataSource = tasks;
            } watch.Stop();
            MessageBox.Show("EntityFramework.Extension耗时:" + watch.ElapsedMilliseconds);
        }
예제 #4
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);
        }
예제 #5
0
 private void button2_Click(object sender, EventArgs e)
 {
     using (var db = new PermissionEntities())
     {
         db.tb.Where(u => u.name.Contains("4")).Delete();
     }
 }
예제 #6
0
 private void button2_Click(object sender, EventArgs e)
 {
     using (var db = new PermissionEntities())
     {
         var tbs = db.tb.Where(t => t.name == "100").FirstOrDefault();
         tbs.password = "******";
         db.SaveChanges();
     }
 }
예제 #7
0
 private void button2_Click(object sender, EventArgs e)
 {
     using (var enty = new PermissionEntities())
     {
         var lambda = lambdaBuilder1.BuildLambda <Bse_User>();
         var users  = enty.Bse_User.AsQueryable().Where(lambda).ToList();
         dataGridView1.DataSource = users;
     }
 }
예제 #8
0
 private List <tb> DoQuery()
 {
     using (var db = new PermissionEntities())
     {
         var       tbs   = db.tb.Where(p => p.name.Contains("1")).OrderBy(p => p.name);
         List <tb> lstTb = tbs.ToList();
         return(lstTb);
     }
 }
예제 #9
0
 private void FrmLambdaBuilderTest_Load(object sender, EventArgs e)
 {
     using (var enty = new PermissionEntities())
     {
         var users = enty.Bse_User.ToList();
         dataGridView1.DataSource = users;
     }
     lambdaBuilder1.Init <Bse_User>(dataGridView1);
 }
예제 #10
0
 private void button6_Click(object sender, EventArgs e)
 {
     //原生支持
     using (var db = new PermissionEntities())
     {
         //db.tb.SqlQuery
         //db.Database.SqlQuery
         var tbs = db.Database.ExecuteSqlCommand("update tb set password='******' where name='100'");
     }
 }
예제 #11
0
        private List <tb> DoQuery2()
        {
            using (var db = new PermissionEntities())
            {
                var       tbs   = db.Database.SqlQuery <tb>("select * from tb");
                List <tb> lstTb = tbs.ToList();

                return(lstTb);
            }
        }
예제 #12
0
 private List <tb> DoQuery1()
 {
     using (var db = new PermissionEntities())
     {
         var tbs = from tbContext in db.tb
                   where tbContext.name.Contains("2")
                   orderby tbContext.name
                   select tbContext;
         List <tb> lstTb = tbs.ToList();
         return(lstTb);
     }
 }
예제 #13
0
 private void button4_Click(object sender, EventArgs e)
 {
     using (var db = new PermissionEntities())
     {
         db.tb.Update(
             u => u.name.Contains("2"),
             u2 => new tb {
             password = "******"
         });
         //或者  db.tb.Where(u => u.name == "2").Update(u => new tb { password = "******" });
     }
 }
예제 #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            string name = dataGridView1.CurrentRow.Cells[0].Value.ToString();

            using (var db = new PermissionEntities())
            {
                db.tb.Where(u => u.name == name).Delete();
                //或者
                // db.tb.Delete(u => u.name == "101");
                //不需要db.SaveChanges();
            }
        }
예제 #15
0
        private void button8_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();
            using (var db = new PermissionEntities())
            {
                db.tb.Where(t => t.name.Contains("2")).OrderBy(t => t.name).AsNoTracking().ToList();
            } watch.Stop();
            MessageBox.Show("耗时:" + watch.ElapsedMilliseconds);
        }
예제 #16
0
파일: Program.cs 프로젝트: thinhils/Nikita
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     using (var dbcontext = new PermissionEntities())
     {
         var objectContext     = ((IObjectContextAdapter)dbcontext).ObjectContext;
         var mappingCollection = (StorageMappingItemCollection)objectContext.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
         mappingCollection.GenerateViews(new List <EdmSchemaError>());
     }
     Application.Run(new FrmMainBase());
 }
예제 #17
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();
     }
 }
예제 #18
0
        private void button5_Click(object sender, EventArgs e)
        {
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();
            using (var db = new PermissionEntities())
            {
                var query = db.tb.Where(t => true).OrderBy(t => t.name);
                //用skip之前必须OrderBy
                PagerResultModel <tb> tbs = PagerExtension.ToPager <tb>(query, 1000, int.Parse(textBox1.Text.Trim()));

                label1.Text = tbs.Count.ToString();
                dataGridView1.DataSource = tbs.List;
            } watch.Stop();
            MessageBox.Show("ExfSoft.EntityFramework.Extension耗时:" + watch.ElapsedMilliseconds);
        }
예제 #19
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("成功");
        }
예제 #20
0
        private void button5_Click(object sender, EventArgs e)
        {
            using (var db = new PermissionEntities())
            {
                //看看EF EL怎么解决
                // 复用的查询

                // base query
                var q = db.tb.Where(t => t.name.Contains("1"));
                // get total count
                var q1 = q.FutureCount();
                // get page
                var q2 = q.OrderBy(t => t.name).Skip((int.Parse(textBox1.Text.Trim()) - 1) * 10).Take(10).Future();
                // triggers execute as a batch
                int total = q1.Value;
                var tasks = q2.ToList();

                label1.Text = total.ToString();
                dataGridView1.DataSource = tasks;
            }
        }
예제 #21
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);
        }