简体   繁体   English

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

[英]Entity Framework 6 - Select Parents Where Children Equal

I just need Parent objects. 我只需要Parent对象。 In SQL, this is simple: 在SQL中,这很简单:

select distinct * from parent 
join child on child.ParentID = Parent.ID 
where child.playssoccer = true;

In Entity Framework 6, this seems like splitting the atom to me. 在实体框架6中,这似乎将原子分裂给我。

I need new p => parent where parents.children.playssoccer = true . 我需要新的p => parent,其中parents.children.playssoccer = true。

How do I get soccer parents out of a similar EF6 DBContext? 如何从类似的EF6 DBContext中获取足球父母?

from p in context.Parents
where p.Children.Any(c => c.PlaySoccer == true)
select p

This is assuming you want parents who have at least one child that plays soccer. 这假设您希望父母至少有一个孩子踢足球。

如果你有导航属性,你可以做类似的事情

Parents.Where(p => p.child.playsoccer)
Parents
.Where(p=> p.child.playsoccer)
.GroupBy(p=> p.Parent.ID)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM