4

I just need Parent objects. In SQL, this is simple:

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.

I need new p => parent where parents.children.playssoccer = true .

How do I get soccer parents out of a similar EF6 DBContext?

2
  • Thanks, everybody! Paul Abbott's answer worked for me, so I'm giving him the checkmark. Everybody gets upvote, tho. I appreciate the timely responses. Commented May 9, 2014 at 18:27
  • 1
    Actually your question isn't about EF , it's about Linq usage: ) Commented May 9, 2014 at 19:17

3 Answers 3

8
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.

Sign up to request clarification or add additional context in comments.

Comments

3

If you have navigation properties you can do something like

Parents.Where(p => p.child.playsoccer) 

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.