贴上一段代码:
bureaucraticEntities apply = new bureaucraticEntities();
Type tapp= app.GetType();
Type ttmp = tmp.GetType();
List<PropertyInfo> tList= tapp.GetProperties().ToList();
List<PropertyInfo> tmpList = ttmp.GetProperties().ToList();
for (int i = 0; i < tmpList.Count; i++)
{
//根据属性名获得指定的属性对象
PropertyInfo gc = ttmp.GetProperty(tList[i].Name);
//获取app的值
//设置tmp属性
if (tList[i].Name != "Base_id")
gc.SetValue(tmp, tList[i].GetValue(app, null), null); }
apply.SaveChanges();
注:app和tmp是同一个类的不同对象,类形不同方法也类似吧。本demo是用ef做的