我需要帮助解决一个我想不明白的问题。我想要一份只有没有回答的问题的调查问卷。
要清楚,一个人应该能够要求一份问卷,回答一个问题,比如说,总共5个问题。然后,当一个人下次请求问卷时,它应该返回,但只有4个问题(未回答的问题)。
我试过它与lambda包括也,但不能让它工作。任何帮助都是非常感激的!
类的结构类似于
public class Questionnaire()
{
public int Id {get; set;}
public List<Question> {get; set;}
}
public class Question()
{
public int Id {get; set;}
public int QuestionnaireId {get; set;}
public List<Answer> {get; set;}
}
public class Answer()
{
public int Id {get; set;}
public int QuestionId {get; set;}
public int QuestionnaireId {get; set;}
public List<ReceivedAnswer> {get; set;}
}
public class ReceivedAnswer()
{
public int AnswerId {get; set;}
public int QuestionId {get; set;}
public int QuestionnaireId {get; set;}
public int PersonId {get; set;}
}
假设您有表:
Questionnaires[QuestionnairesID, QuestionID]
ReceivedAnswers[PersonID , AnswerID]
Questions[QuestionID,Question]
Answers[AnswerID,QuestionID,Answer]
Linq查询将像:
var pp = (from q in questionnaire.Questions
join a in question.Answers on q.questionid equals a.questionid
join ra in ReceivedAnswers on ra.answerid equals a.answerid
where ra.personid == inPersonID
select q.questionid).ToList();
var output = from questionnaire in _unitOfWork.Questionnaires
where questionnare.Id == questionnaireId && !pp.contains(q.questionid)
select questionnaire