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 - I understand your reply however I'd like this in a query to select nodes which have a value set for the Content Picker. The complete code for the selection is
Dim cManufacturers = From n In New UmbracoHelper(UmbracoContext.Current).TypedContent(ProductDataFolder(0).Id).Descendants.AsEnumerable
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"
Select n
I'd like to select nodes with a particular variable in the Content Picker, ignoring nodes without a value.
I still haven't been able to work out a solution to my original post but see it comes down to a much simpler question: is it possible to both check that a property value exists and also evaluate the same property (if it has a value) within a LINQ WHERE clause?
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!
Hi Steve,
You have to check your values for null. Sorry this code isn't VB, but I think you will understand ))
Thanks, Alex
Hi Alex,
Thanks - I understand your reply however I'd like this in a query to select nodes which have a value set for the Content Picker. The complete code for the selection is
I'd like to select nodes with a particular variable in the Content Picker, ignoring nodes without a value.
Best regards /Steve
Hi All,
I still haven't been able to work out a solution to my original post but see it comes down to a much simpler question: is it possible to both check that a property value exists and also evaluate the same property (if it has a value) within a LINQ WHERE clause?
Any assistance would be greatly appreciated.
Thanks,Steve
Having a similar challenge. Would love to see a solution to this problem.
is working on a reply...