var query = from g in root.Groups from r in g.Rules from c in r.Conditions from a in c.Actions where a.ActionID == ActionId select a; List<RuleAction> items = query.ToList(); RuleAction RetVal = items[0];It could also be expressed this way:
RuleAction action = null; foreach (RuleGroup g in root.Groups) { foreach (Rule r in g.Rules) { foreach (RuleCondition c in r.Conditions) { foreach (RuleAction a in c.Actions) { if (a.ActionID == ActionId) { action = a; break; } } } } }The problem is that each collection could be null. In this case, it crashes on the foreach (RuleCondition c in r.Conditions) because r.Conditions has nothing in it.