I have an EF DB context query that produces a list of objects that look like this:
public interface Parent
{
public string Name { get; set; }
public virtual ICollection<Child> Children {get; set;}
}
public interface Child
{
public string Name {get; set;}
public boolean isValid {get; set;}
}
The query itself looks like
var list _dbContext.Parents.Include(x => x.Children).ToList();
I want to be able to query each parent, pull out the details of each child that has isValid = true
and then store them all in a list, but I can't figure out the syntax.
I was trying to do something like
list.Where(x => x.Children.Where(child => child.isValid).toList()).toList();
But the above just produces an IList<IList>