public void AddStudent(StuInfoTable stuTable)
        {
            StudentsInfoDBEntities StuDB = new StudentsInfoDBEntities();
               try
               {
               IDataAccess idata = new DataServerse();
               int getId = idata.Search((StuInfoTable stu) => stu.ID == stuTable.ID).Take(1).Count();
               if (getId != 1)
               {
                   StuDB.StuInfoTable.Add(stuTable);
                   StuDB.SaveChanges();
                   MessageBox.Show("成功添加1条信息!");
               }
               else
                   MessageBox.Show("学号已存在!");

               }
               catch (Exception e)
               {
               MessageBox.Show("添加数据发生异常:" + e.Message);
               }
               finally
               {
               StuDB.Dispose();
               }
        }
 public List<StuInfoTable> Search(Func<StuInfoTable,bool> queryFunc)
 {
     List<StuInfoTable> result = new List<StuInfoTable>();
     StudentsInfoDBEntities StuDB = new StudentsInfoDBEntities();
     try
     {
         result = StuDB.StuInfoTable.Where(queryFunc).ToList<StuInfoTable>();
     }
     catch(Exception e)
     {
         MessageBox.Show("查询出现错误:" + e.Message);
     }
     finally
     {
         StuDB.Dispose();
     }
     return result;
 }
        public int DeleteStudent(StuInfoTable stuTalbe)
        {
            StudentsInfoDBEntities stuDB = new StudentsInfoDBEntities();
            int result = 0;
            try
            {
                //List<StuInfoTable> stuEnu = stuDB.StuInfoTable.Where(item => item.ID == stuTalbe.ID).ToList<StuInfoTable>();
                //StuInfoTable stu = stuEnu[0];

                stuDB.StuInfoTable.Attach(stuTalbe);

                stuDB.StuInfoTable.Remove(stuTalbe);
                result= stuDB.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show("删除出现错误:" + e.Message);
            }
            finally
            {
                stuDB.Dispose();
            }
            return result;
        }