1

I am facing problem, I write a query in Entity Framework Core using C#, but I am unable to get my final result. It will be great favour if someone help me.

I want to show students result of entry test, if subject result is not posted then it should show 0, means need to add left outer join. I write the below query, but when I execute it returns the error.

var result = _db.palSundayTests
                .Where(w => w.testId == testId)
                .Select(s => new
                             {
                                 testId = s.testId,
                                 testDate = s.testDate,
                                 students = _db.palSundayTestStudents
                                               .Where(w => w.testGroupId == s.testGroupId)
                                               .Select(st => new
                                                             {
                                                                 students = st,
                                                                 results = (from tp in _db.palSubjInfo
                                                                            join rs in _db.palStudentTestResult.Where(r => r.studentId == st.studentId)
                                                                                 on tp.subjectId equals rs.subjectId
                                                                            into myres 
                                                                            from myview in myres.DefaultIfEmpty()
                                                                            select new
                                                                                   {
                                                                                       myview.obtainedMarks
                                                                                   }).ToList()
                                                              }).FirstOrDefault(),
                                 subjects = s.sundayTestTopic
                             });

When I run in POSTMAN, I get this error

The multi-part identifier "t.subjectId" could not be bound
The multi-part identifier "t.obtainedMarks" could not be bound
The multi-part identifier "t.studentId" could not be bound
The multi-part identifier "t.testId" could not be bound

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

You are mixing implicit joins with explicit joins. That is allowed, but you need to be aware of how to do that properly. may it help https://stackoverflow.com/a/7314936/11143288