Dodsworth
asked on
Linq Where Problem
I'm trying to use..
but I get
A first chance exception of type 'System.NullReferenceExcep tion' occurred
If I remove the where clause there are no problems and I can see items with a surname starting with D.
What is going wrong ?
Dim subListItems = From items In listIn Where items.Surname.StartsWith("D")
but I get
A first chance exception of type 'System.NullReferenceExcep
If I remove the where clause there are no problems and I can see items with a surname starting with D.
What is going wrong ?
Probably one of the "items" has a null value for surname.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I don't want to 'ignore' null items though. Ideally I'd like them to be grouped with items that have a zero length string as a surname. Is that linq-able?
Dim abc As dynamic = From p In listIn Where p.Name IsNot Nothing Where p.Name.StartsWith("D")
The whole POINT of using a where clause is to ignore items....originally you wanted to ignore all items where the surname did not start with "D".
If you are trying to do groupings you probably should be working with group ... by clauses.
You can adapt pretty much anything to LINQ....you can always write a function that takes an object and does arbitrary processing to do a yes/no (use/ignore) decision (a PREDICATE for a where clause) or that returns some useful value (for a group .. by clause).
If you are trying to do groupings you probably should be working with group ... by clauses.
You can adapt pretty much anything to LINQ....you can always write a function that takes an object and does arbitrary processing to do a yes/no (use/ignore) decision (a PREDICATE for a where clause) or that returns some useful value (for a group .. by clause).