实体框架6 - 选择孩子平等的父母

Joh*_*gan 3 c# linq entity-framework-6

我只需要Parent对象.在SQL中,这很简单:

select distinct * from parent 
join child on child.ParentID = Parent.ID 
where child.playssoccer = true;
Run Code Online (Sandbox Code Playgroud)

在实体框架6中,这似乎将原子分裂给我.

我需要新的p => parent,其中parents.children.playssoccer = true.

如何从类似的EF6 DBContext中获取足球父母?

Pau*_*ott 7

from p in context.Parents
where p.Children.Any(c => c.PlaySoccer == true)
select p
Run Code Online (Sandbox Code Playgroud)

这假设您希望父母至少有一个孩子踢足球.