Nic
Nic

Reputation: 501

Get value from db in list

I have following code. It is giving me list of events. In that I want get patient name.

I have patient Id, but I am confused how can I get patient name using that id.

events = db.PTSessions.Where(x => x.OfficeIdFk == user.OfficeIdFk || x.PTIdFk == user.PTId).Where((a => a.AppointmentDate > start &&
                (a.AppointmentTimeTo < end))).Select(m => new EventViewModel
                {
                    id = m.SessionId,
                    title = m.AppointmentReason,
                    start = m.AppointmentTimeFrom,
                    end = m.AppointmentTimeTo,
                    allDay = false,
                    patientid = m.PatientIdFk,
                    appointmentstatus = m.AppointmentStatus,
                    patientname = db.Patients.Where(p => p.PatientId == m.PatientIdFk).Select(p => p.PatientName).ToString()
                }).ToList();

in above code I can't get patientname and getting error also.

Thanks

Upvotes: 0

Views: 67

Answers (1)

Serge
Serge

Reputation: 43860

try this

patientname = db.Patients.Where(p => p.PatientId == m.PatientIdFk)
.Select(p => p.PatientName).FirstOrDefault()

Upvotes: 2

Related Questions