/// <summary> /// 修改员工的方法 /// </summary> /// <param name="_em"></param> /// <returns></returns> public bool Update(EmployeeInfo _em) { //拿到当前对象 var me = t.Entry <EmployeeInfo>(_em); //设置状态 me.State = System.Data.EntityState.Unchanged; //得到当前泛型类的所有属性 PropertyInfo[] pt = _em.GetType().GetProperties(); for (int i = 0; i < pt.Length; i++) { //拿到要更新的字段 object obj = pt[i].GetValue(_em); //更新 if (obj != null) { me.Property(pt[i].Name).IsModified = true; } } return(t.SaveChanges() > 0); }