Select documents with where clause evaluating content picker

I need to select a list of documents which have a particular value in a Content Picker data type. I seem to have this working except that some of the documents being evaulated do not have values for this field, so getting an error 'Object reference not set to an instance of an object'

How can I check if the property 'hasvalue' and also evaluate (if it does) in the same where clause?

at the moment I have something similar to:

Where n.DocumentTypeAlias = "Manufacturer" And n.Parent.Name = "Product Data" And n.HasValue("parentManufacturer") And New UmbracoHelper(UmbracoContext.Current).TypedContent(n.GetPropertyValue("parentManufacturer").ToString()).Name = "Test"

 

Using Umbraco 7.1.3 / code is vb in a user control in this case

Thanks!          


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/64310-select-documents-with-where-clause-evaluating-content-picker