Beispiel #1
0
 /// <summary>
 /// 查询实例
 /// </summary>
 /// <returns></returns>
 public void select()
 {
     using (var entity = new ccf02Entities())
     {
         //DataTable dataTable = entity.person_test;
         DbSet dt = entity.person_test;
     }
 }
Beispiel #2
0
        /// <summary>
        /// 添加实例
        /// </summary>
        /// <param name="student"></param>

        public void Insert(person_test p)//可以添加一个entity 参数
        {
            using (var entity = new ccf02Entities())
            {
                entity.person_test.Add(p);
                entity.SaveChanges();
            }
        }
Beispiel #3
0
 /// <summary>
 /// 修改实例
 /// </summary>
 /// <param name="model"></param>
 public void Edit(person_test model)
 {
     using (var entity = new ccf02Entities())
     {
         entity.Entry(model).State = EntityState.Modified;
         entity.SaveChanges();
     }
 }
Beispiel #4
0
        /// <summary>
        /// 删除某一条数据
        /// </summary>
        /// <param name="id"></param>
        public void Deleted(int id) //添加两个参数entity & table
        {
            using (var entity = new ccf02Entities())
            {
                person_test p = new person_test()
                {
                    idperson_test = id
                };

                var model = entity.person_test.FirstOrDefault(w => w.idperson_test == id);
                entity.person_test.Remove(model);
                entity.SaveChanges();
            }
        }
Beispiel #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var db = new ccf02Entities())
            {
                //刷新 dgv1
                this.dataGridView1.Invalidate();
                //var info = db.UserInfo.Where(c => c.Age > 10).OrderBy(c => c.Age);
                //var res = db.person_test.Where(a => a.age == 12).OrderBy(a => a.name);
                var res = db.person_test;
                foreach (var info in res)
                {
                    //db.Entry(info).Collection() ;
                    //richTextBox1.AppendText(info.name.ToString()+"\r\n");
                }
                // Will hit the database
                var blog = db.person_test.Find(3);

                // Will return the same instance without hitting the database

                //db.person_test.Add(new person_test { idperson_test=8,age = 31, name = "generate", sex = "m" });
                //db.person_test.Add(new person_test { idperson_test=9,age = 31, name = "generate", sex = "m" });

                // Will find the new blog even though it does not exist in the database
                //delp.name = "ff";
                //delp.idperson_test = 0;
                //db.person_test.Attach(delp);
                //db.Entry(delp).State = System.Data.Entity.EntityState.Modified;
                //MessageBox.Show(db.Entry(delp).State.ToString());
                //db.Entry(delp).State = System.Data.Entity.EntityState.Deleted;
                //var newBlog = db.person_test.Remove(delp);

                db.SaveChanges();

                // Will find a User which has a string primary key
                //var user = db.person_test.Find("neo");
                //var s = db.person_test.Find(0);
                //this.dataGridView1.Refresh();
                this.person_testTableAdapter.Fill(this.ccf02DataSet.person_test);
            }

            BindingandDisplay();
        }