Copied to clipboard

Flag this post as spam?

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


  • Jesper Skjønnemand 16 posts 168 karma points
    Feb 07, 2019 @ 12:08
    Jesper Skjønnemand
    0

    problem with Where(something && something)

    I am having trouble filtering the items on a list page. The selection below works fine, but it displays every "person" under "people".

    var selection = Model.Content.Site().FirstChild("people").Children("person").Where(x => x.IsVisible()).OrderBy(x => x.GetPropertyValue("personFirstName")).ThenBy(x => x.GetPropertyValue("personLastName")).ToArray();;
    

    I need the selection to display only items ("person") where the property "personInternal" is TRUE.

    I have tried various things without success (Runtime Error):

    Where(x => x.IsVisible() && x => x.person.personInternal.Equals("TRUE"))
    Where(x => x.IsVisible() && x => x.person.personInternal.Is("TRUE"))
    Where(x => x.IsVisible() && x => x.person.personInternal == "TRUE")
    Where(x => x.IsVisible() && x => x.person.personInternal.Equals(TRUE))
    Where(x => x.IsVisible() && x => x.person.personInternal.Is(TRUE))
    Where(x => x.IsVisible() && x => x.person.personInternal == TRUE)
    
    Where(x => x.IsVisible() && x.person.personInternal.Equals("TRUE"))
    Where(x => x.IsVisible() && x.person.personInternal.Is("TRUE"))
    Where(x => x.IsVisible() && x.person.personInternal == "TRUE")
    Where(x => x.IsVisible() && x.person.personInternal.Equals(TRUE))
    Where(x => x.IsVisible() && x.person.personInternal.Is(TRUE))
    Where(x => x.IsVisible() && x.person.personInternal == TRUE)
    
    Where(x => x.IsVisible() && person.personInternal.Equals("TRUE"))
    Where(x => x.IsVisible() && person.personInternal.Is("TRUE"))
    Where(x => x.IsVisible() && person.personInternal == "TRUE")
    Where(x => x.IsVisible() && person.personInternal.Equals(TRUE))
    Where(x => x.IsVisible() && person.personInternal.Is(TRUE))
    Where(x => x.IsVisible() && person.personInternal == TRUE)
    
    Where(x => x.IsVisible() && personInternal.Equals("TRUE"))
    Where(x => x.IsVisible() && personInternal.Is("TRUE"))
    Where(x => x.IsVisible() && personInternal == "TRUE")
    Where(x => x.IsVisible() && personInternal.Equals(TRUE))
    Where(x => x.IsVisible() && personInternal.Is(TRUE))
    Where(x => x.IsVisible() && personInternal == TRUE)
    

    What am I doing wrong? Any suggestions?

    Best

  • Kevin Jump 1346 posts 8363 karma points MVP 2x c-trib
    Feb 07, 2019 @ 12:18
    Kevin Jump
    0

    Hi Jesper

    try

    Where(x => x.IsVisible() && x => x.GetPropertyValue<bool>("personInternal"))
    

    K

  • Jesper Skjønnemand 16 posts 168 karma points
    Feb 07, 2019 @ 12:39
    Jesper Skjønnemand
    0

    Hi Kevin

    I still get Runtime Error. I tested various strings:

     && x => x.GetPropertyValue<bool>("personInternal")
     && x => x.GetPropertyValue<bool>("personInternal") == TRUE
     && x => x.GetPropertyValue<bool>("personInternal").Equals(TRUE)
     && x => x.GetPropertyValue<bool>("personInternal") == "TRUE"
     && x => x.GetPropertyValue<bool>("personInternal").Equals("TRUE")
    

    Suppose none of those are what you meant (?)

  • Alex Skrypnyk 5174 posts 18864 karma points MVP 2x admin c-trib
    Feb 07, 2019 @ 13:05
    Alex Skrypnyk
    0

    Hi Jesper,

    Try to print "personInternal" value or debug what is the value of this property?

    Alex

  • Marcio Goularte 319 posts 1073 karma points
    Feb 07, 2019 @ 12:47
    Marcio Goularte
    0

    Try

    Where(x => x.IsVisible() && x => x.GetPropertyValue<string>("personInternal").Equals("1"))
    
  • Alex Skrypnyk 5174 posts 18864 karma points MVP 2x admin c-trib
    Feb 07, 2019 @ 13:04
    Alex Skrypnyk
    0

    Marcio, you provided code with a mistake, it should be at least:

    .Where(x => x.IsVisible() && x.GetPropertyValue<string>("personInternal").Equals("1"))
    
  • Jesper Skjønnemand 16 posts 168 karma points
    Feb 07, 2019 @ 13:20
    Jesper Skjønnemand
    102

    this worked

    .Where(x => x.IsVisible() && x.GetPropertyValue<string>("personInternal").Equals("True"))
    
Please Sign in or register to post replies

Write your reply to:

Draft