I have four Tables
Question Table
| Id | QuestionCode | GroupId |
|---|---|---|
| 1 | 101 | 3 |
| 2 | 102 | 3 |
| 3 | 103 | 3 |
| 4 | 104 | 3 |
| 5 | 105 | 3 |
Exam Table
| Id | Exam Name | GroupId |
|---|---|---|
| 1 | Main Exam | 3 |
User Table
| Id | UserId | ExamId |
|---|---|---|
| 1 | 1001 | 1 |
Answer Table
| Id | UserId | ExamId | Questioncode | UserAnswer | RightAnswer | Attempted | RemainingQuestionTime |
|---|---|---|---|---|---|---|---|
| 1 | 1001 | 1 | 101 | A | A | true | 56 |
here I am fetching data from Question table where if student question is not in the answer table then from the particular exam may fetch next questions. My query is
var QuestionList =
(from q in db.Question
from e in db.Exam
where q.GroupId == e.GroupId
from u in db.User
where e.Id == u.ExamId
where !db.Answer.Any(x => x.UserId == u.UserId && x.ExamId == e.Id && x.QuestionCode == q.QuestionCode)
select new
{
q
}).FirstOrDefault();
I am not getting desired result. So please help.