DataRow转为实体

把包含 对象 数据的DataRow转换成 实体对象(泛型反射方式)
 public static T Row2Model<T>(DataRow dr) where T : new()
 {
      T model = new T();
      foreach (PropertyInfo p in (typeof(T)).GetProperties())
       {
            if (dr[p.Name] is System.DBNull) { break; }
            p.SetValue(model, dr[p.Name], null);
       }
       return model;
}

 

posted @ 2015-12-16 23:16  Leo的日记本  阅读(1363)  评论(0编辑  收藏  举报