Linq Where Problem

I'm trying to use..

Dim subListItems = From items In listIn Where items.Surname.StartsWith("D")

Open in new window


but I get

A first chance exception of type 'System.NullReferenceException' 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 ?
LVL 1
DodsworthAsked:
Who is Participating?
 
Jens FiedererTest Developer/ValidatorCommented:
you could try
Where items.Surname isnot Nothing andalso items.surname.StartsWith("D")
0
 
Jens FiedererTest Developer/ValidatorCommented:
Probably one of the "items" has a null value for surname.
0
 
DodsworthAuthor Commented:
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?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jayakrishnabhCommented:
Dim abc As dynamic = From p In listIn Where p.Name IsNot Nothing Where p.Name.StartsWith("D")
0
 
Jens FiedererTest Developer/ValidatorCommented:
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).
0
 
Jens FiedererTest Developer/ValidatorCommented:
Some examples of using grouping operators are at


http://msdn.microsoft.com/en-us/vstudio/bb737908
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.