Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem With Linq Query
Message
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
Problem With Linq Query
Divers
Thread ID:
01467354
Message ID:
01467354
Vues:
79
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
Répondre
Fil
Voir

Click here to load this message in the networking platform