Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can This be Done Using Linq?
Message
De
03/05/2010 18:59:01
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01462904
Message ID:
01462921
Vues:
51
>I have 3 nested collections:
>
>
>internal RuleCondition GetCondition(int ConditionId)
>{
>    RuleCondition RetVal = null;
>
>    foreach (RuleGroup Group in _root.Groups)
>    {
>        foreach (Rule rule in Group.Rules)
>        {
>            foreach (RuleCondition Condition in rule.Conditions)
>            {
>                if (Condition.ConditionID == ConditionId)
>                {
>                    RetVal = Condition;
>                    break;
>                }
>            }
>        }
>    }
>
>    return RetVal;
>}
>
>
>Can I pulll the Condition using Linq so I don't have to iterate through the 3 collections?
var condition = ( from grp in _root.Groups
                        from rule in grp.Rules
                        from cnd in rule.Conditions
                        select cnd)
                    .FirstOrDefault( x => x.ConditionID == ConditionId);
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform