Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can This be Done Using Linq?
Message
From
03/05/2010 18:59:01
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01462904
Message ID:
01462921
Views:
52
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform