private void SetModelValue(BaseModel model, SqlDataReader dr)
{
Type t = this.GetType();
PropertyInfo[] myPropertyInfo;
myPropertyInfo = t.GetProperties(); for (int i = 0; i < myPropertyInfo.Length; i++)
{
//实体类中定义了可空数据类型就过不去,不定义可空类型就能过去 为什么?
myPropertyInfo[i].SetValue(model, ValueConversion.ConvertDBNullValue(dr[myPropertyInfo[i].Name]), null);
}
}
}这是一个给实体类赋值的方法
{
Type t = this.GetType();
PropertyInfo[] myPropertyInfo;
myPropertyInfo = t.GetProperties(); for (int i = 0; i < myPropertyInfo.Length; i++)
{
//实体类中定义了可空数据类型就过不去,不定义可空类型就能过去 为什么?
myPropertyInfo[i].SetValue(model, ValueConversion.ConvertDBNullValue(dr[myPropertyInfo[i].Name]), null);
}
}
}这是一个给实体类赋值的方法
object obj = dr[dr[myPropertyInfo[i].Name]
if(obj != null)
{
myPropertyInfo[i].SetValue(model,obj,null);
}
判断了,问题不在obj,问题是model的属性是可空类型,不能被SetValue这个方法赋值