C# 从数据库中获取主键

C# 从数据库中获取主键,c#,html,asp.net,c#-4.0,frontend,C#,Html,Asp.net,C# 4.0,Frontend,我创建了一个方法,该方法在重复结构中遍历从主键返回的数据,但出现以下错误,无法将类型“System.Attribute”隐式转换为“bool” 因为这一行:this.GetType().GetProperty(pro.Name).GetCustomAttribute(typeof(DataObjectFieldAttribute)将返回一个System.Attribute,但是if正在查找一个bool 你不想加一张支票吗 if (this.GetType().GetProperty(pro.Na

我创建了一个方法,该方法在重复结构中遍历从主键返回的数据,但出现以下错误,无法将类型“System.Attribute”隐式转换为“bool”


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

你不想加一张支票吗

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

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

你不想加一张支票吗

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

我能够解决这个问题,我把null的不同放在亲属关系结束之前,我把null的不同放在亲属关系结束之后,感谢你们的帮助,我能够解决这个问题,我把null的不同放在亲属关系结束之前,我把null的不同放在亲属关系结束之后,然后工作谢谢你的帮助