0

I have three tables. Question, Discipline and QuestionHasDiscipline. QuestionHasDiscipline holds the relation between Question and Discipline. They all have an unique id-column to identify them.

I am trying to write a linq-statement that returns all the questions that have a certain discipline.

What I have begun doing is this:

               var questions = (from q in context.Questions
                             where (from d in context.QuestionHasDiscipline
                                    where d.QuestionId == q.QuestionId
                                    ) ...

But it obviously is horribly wrong. I've tried different approaches but now I turn to the greater minds.. Any suggestions?

1

1 Answer 1

2

You can use .Any() with a predicate.

from q in context.Questions
where context.QuestionHasDiscipline.Any(d => d.QuestionId == q.QuestionId)
select q;
1
  • Just gotta say, I keep coming back to this one and it saves me everytime. Thanks again!
    – Phil
    Jul 25, 2011 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.