简体   繁体   中英

How to write IQueryable join in Entity Framework 6

I do have this code but I want to do it in IQueryable:

var select = (from g in this.context.Grades
              join sm in this.context.SubjectMaintenance on g.SubjectCode equals sm.SubjectCode
              join st in this.context.Students on g.StudentId equals st.StudentId
              where sm.TeacherId == sTeacherId
              select new
                     {
                         SubjectCode = g.SubjectCode,
                         SubjectName = g.SubjectName,
                         StudentName = st.LastName + ", " + st.Firstname,
                         PrelimGrade = g.PrelimGrade,
                         MidtermGrade = g.PrelimGrade,
                         FinalGrade = g.PrelimGrade,
                     }).ToList();

How do I write it using IQueryable ? My start code for IQueryable is this:

IQueryable<Grades> query = this.context.Grades;

IQueryable<SubjectMaintenance> query1 = this.context.SubjectMaintenance;
IQueryable<Students> query2 = this.context.Students;

Please do help as I need it in my project. Thank you in advance for your help.

You can follow the below logic to write your query.

var query1 = 
var query2 = 
var join = query1.Join(query2, x => x.ParentId, y => y.ParentId, (query1, query2) => new { query1, query2 })

Please follow this document also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM