I have a question for you linq experts out there!
In a nested list of Component instances, I need to know if there is a component of a particular type in it. Can it be expressed by linq? Take into account that there may be application.Components[0].Components[0].Components[0]… My question is oriented to recursive queries in linq!
I leave you the entities for you to have some idea of the model.
public class Application
{
public List<Component> Components { get; set; }
}
public class Component
{
public ComponentType Type { get; set; }
public List<Component> Components { get; set; }
}
public enum ComponentType
{
WindowsService,
WebApplication,
WebService,
ComponentGroup
}
You want to know if any of the components in a component is of a given type?
Edit: So you want to find components of a given type recursively not only on the top or second level. Then you can use following
Traverseextension method:to be used in this way:
sample data: