从数据库中获取主键

时间:2017-07-28 01:50:04

标签: c# html asp.net c#-4.0 frontend

我创建了一个遍历重复结构中从主键返回的数据的方法,但发生以下错误,无法隐式转换类型" System.Attribute"到" bool"

  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data.SqlClient;
  using System.Linq;
  using System.Reflection;
   using System.Web;




   UPDATE
 private void SetSelf(Cliente Entity)
    {

        foreach (PropertyInfo pro in Entity.GetType().GetProperties())
        {

             if (this.GetType().GetProperty(pro.Name).GetCustomAttribute(typeof(DataObjectFieldAttribute != null))
            this.GetType().GetProperty(pro.Name).SetValue(this, pro.GetValue(Entity));

        }

    }

1 个答案:

答案 0 :(得分:0)

因为这一行:this.GetType().GetProperty(pro.Name).GetCustomAttribute(typeof(DataObjectFieldAttribute)将返回System.Attribute,但if正在寻找bool

您不想添加支票吗?

if (this.GetType().GetProperty(pro.Name).GetCustomAttribute(typeof(DataObjectFieldAttribute) != null){
}