Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem With Linq Query
Message
General information
Forum:
ASP.NET
Category:
LINQ
Title:
Problem With Linq Query
Miscellaneous
Thread ID:
01467354
Message ID:
01467354
Views:
78
I have this query:
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.

How can I write the Linq version of this to compensate for this?
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Reply
Map
View

Click here to load this message in the networking platform