I have 3 entities:
Questionnaire.cs
:
public class Questionnaire
{
public int Id { get; set; }
public string Name { get; set; }
Filtering in Include
or IncludeThen
is not supported. Create projection by using Select
:
questionnaire = _context.Questionnaires
.Select(n => new Questionnaire
{
Id = n.Id,
Name = n.Name,
Questions = n.Questions.Select(q => new Question
{
Id = q.Id,
Text = q.Text,
Answers = q.Where(a => a.UserId == userId).ToList()
}).ToList()
})
.FirstOrDefault(qn => qn.Id == questionnaireId);
There is a github issue about this problem: https://github.com/aspnet/EntityFramework/issues/3474