Hello all,
I got stuck on how to write LINQ for joining three different tables as follows:
- tblStudent: student_id, school, class, grade
- tblAwards: school, class, grade, account_number
- tblAccount: account_number, scholarship_amount
Firstly to obtain school, class, grade from tblAwards via student_id between two tables tblStudent and tblAwards. Then get scholarship_amount by joining two tables tblAwards and tblAccount via account_number
public static List<string> getScholarshipsAmt(string studentId)
{
using (DBEntities dbContext = new DBEntities())
{
var partialResult = (from stu in db.tblStudent
join aw in db.tblAwards
on new { A = stu.school, B = stu.class, C = stu.grade } equals new { A = aw.school, B = aw.class, C = aw.grade }
where stu.student_id == studentId
select new
{
aw.school,
aw.class,
aw.grade
}).Distinct()
.OrderBy(aw => aw.school).ThenBy(awa => aw.class).ThenBy(aw => aw.grade);
var lstScholarshipsAmt = (from acct in db.tblAccount
join aw in db.tblAwards
on ...
//Please help LINQ coding here
???
return lstScholarshipsAmt;
}
}Thanks in advance.