Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve 140 posts 321 karma points
    Apr 24, 2015 @ 21:59
    Steve
    0

    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!          

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Apr 24, 2015 @ 22:37
    Alex Skrypnyk
    0

    Hi Steve,

    You have to check your values for null. Sorry this code isn't VB, but I think you will understand ))

    var parentManufacturer = n.GetPropertyValue("parentManufacturer");
    if (parentManufacturer != null)
    {
    var parent = UmbracoHelper(UmbracoContext.Current).TypedContent(n.GetPropertyValue<string>("parentManufacturer"));
    parent.Name = "Test";
    }
    

    Thanks, Alex

  • Steve 140 posts 321 karma points
    Apr 25, 2015 @ 15:43
    Steve
    0

    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

    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.

    Best regards /Steve

  • Steve 140 posts 321 karma points
    May 01, 2015 @ 04:34
    Steve
    0

    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

  • Damian Chambers 23 posts 87 karma points
    Aug 26, 2016 @ 13:58
    Damian Chambers
    0

    Having a similar challenge. Would love to see a solution to this problem.

Please Sign in or register to post replies

Write your reply to:

Draft