我需要从我的 table 上获取特定患者的所有预约,为此我试过,
public List<Appoinment> GetAppoinments() //here Appointment is a class.
{
List<Appoinment> appointments = null;
foreach (DataObject.Appointment appointment in
dataEntities.Appointments.Where(a => a.PATIENTID == PatientId))
{
}
return appointments;
}
在我的约会类和表中,我有像 PatientId、doctorid、约会日期这样的字段,
在这里,在 foreach 循环中,我试过,
appointments.add(appointment);
它的thorwing错误,它不能自动从数据库表约会转换为类约会,对吧。
我不知道该怎么做,谁能帮我解决这个问题,在此先感谢
最佳答案
public List<Appointment> GetAppointments()
{
return dataEntities.Appointments
.Where(a => a.PATIENTID == PatientId)
.Select(a => new OtherNamespace.Appointment
{
Id = a.Id,
Name = a.Name,
// etc.
})
.ToList();
}
关于c# - 从方法返回 <list> 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11206452/