Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Test For Null
Message
From
04/06/2010 14:30:18
 
General information
Forum:
ASP.NET
Category:
LINQ
Title:
Miscellaneous
Thread ID:
01467359
Message ID:
01467381
Views:
35
>>>>>List 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.....
>
>What does <RuleAction> mean in this syntax List<RuleAction> Is it some type?
A generic list. ie. a list that only contains objects of type RuleAction.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform