This will work:
public IEnumerable<Child> GetAllChildren(IEnumerable<Parent> parents)
{
return from parent in parents
from child in parent.Children
select child;
}
and then this:
public IEnumerable<Child> GetAllChildren(IEnumerable<Grandparent> nanas)
{
return from papa in nanas
from parent in papa.Children
from child in parent.Children
select child;
}
Please note that in this example I am not actually returning a list, I am returning an IEnumerable data source which, until you start using it or the like, will not actually process it.
If you need to return a list, modify each return statement as follows:
return (from .....
...
select child).ToList();
source
share