Link to home
Start Free TrialLog in
Avatar of David Glover
David GloverFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How can this FindAll query be reworked to return the combined list of qualifying objects?

In this simple example  below I have some nested lists and I want the root to be able to return a list of the grandchildren that match a predicate.
Class cFruits
    Property Fruits as List(Of cFruit)
    Function VegetarianRecipes() As List(Of cRecipe)
        'The following line is wrong as it returns the cFruits that have a vegetarian Recipe and not the Recipes themselves.  
        'How do I rework the linq to return the cRecipe as one list even though they are sourced from seperate lists?
        Return Fruits.FindAll(Function(f) f.Recipes.FindAll(Function(x) x.Vegetarian = True).Count > 0)
    End Function
End Class
Class cFruit
    Property Recipes as List(Of cRecipe)
End Class
Class cRecipe
    Property Vegetarian As Boolean
End Class

Open in new window

How can the Return line in the Function VegetarianRecipes be modified to return a list of the grandchildren of type cRecipe that are vegetarian.
Thank you,
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial