I'm trying to select a subset of two lists of the same object as part of a where clause, and getting an error.
{"Expression of type 'System.Linq.IQueryable
1[<>f__AnonymousType77
2[System.Int32,System.Int32]]' cannot be used for parameter of type 'System.Linq.IQueryable1[Entity.Entities.QuestionModuleQuestionDto]' of method 'System.Linq.IQueryable
1[Entity.Entities.QuestionModuleQuestionDto] Where[QuestionModuleQuestionDto](System.Linq.IQueryable1[Entity.Entities.QuestionModuleQuestionDto], System.Linq.Expressions.Expression
1[System.Func`2[Entity.Entities.QuestionModuleQuestionDto,System.Boolean]])' (Parameter 'arg0')"}
public async Task<bool> ValidateQuestions(List<QuestionModuleQuestion> questions)
{
var questionModules = await _context.QuestionModule
.Include(qm => qm.Questions)
Where(qm =>
qm.Questions.Select(q => new {q.QuestionId, q.Sequence})
.Intersect(questions.Select(q => new {q.QuestionId, q.Sequence})).Any())
.ToListAsync();
return questionModules.Any(qm => qm.Questions.Count == questions.Count);
}
I rewrote the clause to look like the following, but I'm not too terribly fond of this approach.
var questionModules = await _context.QuestionModule.Include(qm => qm.Questions)
.Where(qm => qm.Questions.Any(qmq => questions.Any(question =>
question.QuestionId == qmq.QuestionId && question.Sequence == qmq.Sequence)))
.ToListAsync();