I use Entity Framework and have this entity mapping:
Parent
- Child 1 (ActiveInd = "Y")
- Child 2 (ActiveInd = "N")
- Child 3 (ActiveInd = "Y")
I want a Linq query similar to this (but one that will work 🙂
Parent parent = (from p in DataContext.Current.Parents
where p.ParentId == _parentId
&& p.Children.Active == true select p).FirstOrDefault();
It should return the following (only the active records):
Parent
- Child 1 (ActiveInd = "Y")
- Child 3 (ActiveInd = "Y")
If you want parents with at least one active child:
If you want parents with all active children:
If you wanted to filter the children as part of the same query you could do something like:
Or