Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Test For Null
Message
General information
Forum:
ASP.NET
Category:
LINQ
Title:
Miscellaneous
Thread ID:
01467359
Message ID:
01467373
Views:
40
>>>I have this:
>>>
>>>
>>>
>>>var query = from g in root.Groups
>>>            from r in g.Rules
>>>            from c in r.Conditions
>>>            from a in c.Actions
>>>            where g.Rules != null
>>>            where r.Conditions != null
>>>            where c.Actions != null
>>>            where a.ActionID == ActionId
>>>            select a;
>>>
>>>List<RuleAction> items = query.ToList();
>>>RetVal = items[0];
>>>
>>>
>>>It fails on the last line with "Object reference not set to an instance of an object" because the query returned no results.
>>>
>>>How do I test for this before attempting to convert the results to a list?
>>
>>Test the items for zero length? Maybe:
>>
>>RetVal = items.Count==0 ? null : items[0];
>
>It's failing on this line:
>
>List<RuleAction> items = query.ToList();
>
Oh. I thought you said the last line :-}
IAC, that seems odd. I just tested with a query with would have no matches and query.ToList() returned an empty List.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform