开发者

has-relation in linq-statement?

开发者 https://www.devze.com 2023-03-12 02:54 出处:网络
I have three tables. Question, Discipline and QuestionHasDisci开发者_Python百科pline. QuestionHasDiscipline holds the relation between Question and Discipline. They all have an unique id-column to ide

I have three tables. Question, Discipline and QuestionHasDisci开发者_Python百科pline. 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?


You can use .Any() with a predicate.

from q in context.Questions
where context.QuestionHasDiscipline.Any(d => d.QuestionId == q.QuestionId)
select q;
0

精彩评论

暂无评论...
验证码 换一张
取 消