user137348
user137348

Reputation: 10332

Linq to Entities : How to filter master table rows based on child rows properties

I have a master table Person and a detail table Events

I need to filter master table rows based on child row property SomeId.

Could anyone please show me how to do it ?

Thanks in advance!

Upvotes: 1

Views: 1213

Answers (2)

Francisco
Francisco

Reputation: 4101

var q = db.Events.Where(p=>p.SomeId == 4).Select(p=>p.Person).Distinct();

Upvotes: 1

user137348
user137348

Reputation: 10332

This works!

var q = from p in db.Persons
        join ev in db.Events on p.Id equals ev.PersonId
        where ev.SomeId == 4
        select p;

Upvotes: 1

Related Questions