我有这个Datareader方法,它确定从数据库中检索的数据,我想知道是否有办法返回PhoneNumber的列表,因为每个Employee在数据库中有几个手机,我想显示而不是单号。这可能吗?。
protected static new Employee LoadReader(IDataRecord dr)
{
Employee e = null;
if (dr != null)
{
e = new Employee
{
FullName = dr.IsDBNull(dr.GetOrdinal("FullName")) ? "" : dr.GetString(dr.GetOrdinal("FullName")),
Age = dr.IsDBNull(dr.GetInt32("Age")) ? 0 : dr.GetInt32(dr.GetOrdinal("Age")),
PhoneNumber = dr.IsDBNull(dr.GetOrdinal("PhoneNumber")) ? "" : dr.GetString(dr.GetOrdinal("PhoneNumber"))
};
}
return e;
}
答案 0 :(得分:0)
protected static new Employee LoadReader(IDataRecord dr)
{
Employee e = null;
if (dr != null)
{
e = new Employee
{
FullName = dr.IsDBNull(dr.GetOrdinal("FullName")) ? "" : dr.GetString(dr.GetOrdinal("FullName")),
Age = dr.IsDBNull(dr.GetInt32("Age")) ? 0 : dr.GetInt32(dr.GetOrdinal("Age"))
};
e.PhoneNumber = LoadPhoneNumbers(e);
}
return e;
}
protected void LoadPhoneNumbers(Employee employee){
* Do a read to the database passing the employee id
* You will receive a reader, this has all your phone number records
* for each record do
employee.PhoneNumbers.Add(the phone number)
}