0

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

3
  • 2
    Include the error description to the post, please. Commented Sep 16, 2021 at 11:32
  • @Jackdaw I am getting this error : The specified type member 'PatientName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. Commented Sep 16, 2021 at 12:08
  • @Nic Do you have proper Relation between PTSessions and Patients entity? if yes then inside PTSession entity you will find Patient entity (x.Patient like this), that will solve your problem Commented Sep 16, 2021 at 12:29

1 Answer 1

2

try this

patientname = db.Patients.Where(p => p.PatientId == m.PatientIdFk)
.Select(p => p.PatientName).FirstOrDefault()
Sign up to request clarification or add additional context in comments.

2 Comments

I tried this and getting this error : The specified type member 'PatientName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
@Nic Pls post Patient class too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.