Dave Bell

Dave Bell

  • 1.5k
  • 108
  • 7.2k

EF Join to fetch data from multiple tables

Mar 16 2023 1:37 AM

I have below entities

Student : Id, Name, .... Event : PId, SId, Name, ... , Subject[] Subject : SId, Name...

I wish to pull all Events and Subjects for given student and include Student Name only from Student

How to I join to get Student Name as well.

So far I have done

_context.event.Where(b => b.SId == request.Id).Include(c => c.Subject)

This gives me list of all Events and Subjects within each Event. How to get Student Id and Name as well...I dont mind it coming for all events.

E.g.
Id, Name, Event1 {Subjects[]},
Id, Name, Event2 {Subjects[]},

Answers (1)