I have 3 objects:
Questionnaire.cs:
public class Questionnaire
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Question> Questions { get; set; }
}
Question.cs:
public class Question
{
public int Id { get; set; }
public string Text { get; set; }
public ICollection<Answer> Answers { get; set; }
}
and Answer.cs:
public class Answer
{
public int Id { get; set; }
public string UserId { get; set; }
public string TextAnswer { get; set; }
}
So, I saved the questionnaire with the answers, but now I want to get a filtered questionnaire with questions and answers. So, I wrote linq for this, but it gives me an error, is there something I am doing wrong? here is an example:
questionnaire = _context.Questionnaires.Include(qn => qn.Questions)
.ThenInclude(question => question.Answers.Where(a => a.UserId == userId))
.FirstOrDefault(qn => qn.Id == questionnaireId);
And I get
Message = "Property Expression" q => {from answer a to q. where Equals ([a] .UserId, __userId_0) select [a]} 'is invalid. the expression should represent access to the properties: 't => t.MyProperty'.
Any ideas how to solve this problem?
user4229770
source
share