Solved

Linq Where Problem

Posted on 2014-04-07
6
191 Views
Last Modified: 2016-02-15
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 ?
0
Comment
Question by:Dodsworth
  • 4
6 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39983137
Probably one of the "items" has a null value for surname.
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 39983146
you could try
Where items.Surname isnot Nothing andalso items.surname.StartsWith("D")
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 39983198
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39983278
Dim abc As dynamic = From p In listIn Where p.Name IsNot Nothing Where p.Name.StartsWith("D")
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39983293
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
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39983296
Some examples of using grouping operators are at


http://msdn.microsoft.com/en-us/vstudio/bb737908
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now