Copied to clipboard

Flag this post as spam?

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


  • Karl Kopp 121 posts 227 karma points
    Mar 25, 2011 @ 02:00
    Karl Kopp
    0

    Search by parent property

    Is it possible to do something like:

    var results = Model.AncestorOrSelf().DescendantsOrSelf("SomeNodeTypeAlias").Where("Parent.SomeProperty = \"Some Value\"");

    ??? I'm just doing it wrong?

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Mar 25, 2011 @ 08:22
    Sebastiaan Janssen
    0

    So what are you actually trying to do? Looks like you want to look at the parent for some value and then want to search the whole site for that property value?

    Just as an example, if you want to get to the parent you can just use Model.Up() and get the property value from that first, then search the whole site.

  • Karl Kopp 121 posts 227 karma points
    Mar 26, 2011 @ 00:19
    Karl Kopp
    0

    I have a bunch of 'specials' that each have a parent venue. What I'm trying to do is find the specials where the parent venue is in a specific city. Make sense?

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Mar 28, 2011 @ 08:13
    Sebastiaan Janssen
    0

    Sorry for the delay:

    Not sure if you could do this in a single-line statement. How about you go find all of the "specials" and iterate through them to filter the ones you need (untested):

    @{
    var specials = Model.AncestorOrSelf().DescendantsOrSelf("special");
    var specialsForCity = new List<DynamicNode>();
    foreach (var node in specials) {
    if (special.Up().CityName == "MyCity") {
    specialsForCity.Add(node);
    }
    }
    }

    This could be a more consise LINQ statement, but let's just see if this works, compacting it down will hinder debugging at first (IMHO).

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Mar 28, 2011 @ 08:17
    Sebastiaan Janssen
    0

    You could also take it the other way around by the way, finding all nodes with your city and then iterating to their children of type "special" might be faster.

  • Karl Kopp 121 posts 227 karma points
    Mar 28, 2011 @ 11:14
    Karl Kopp
    0

    Will give that a whirl tomorrow morn - think finding the parents first then specials may work...

  • Karl Kopp 121 posts 227 karma points
    Feb 17, 2012 @ 01:58
    Karl Kopp
    0

    OK - tried to find all the venues first, then pull out specials (city is parent of venue, venue is parent of special) but something isn't right:

    @using umbraco.MacroEngines;
    @{
      var venues = Model.AncestorOrSelf().DescendantsOrSelf("Venue");
    }
    
    Initial Count: @venues.Count()
    
      @{ venues = venues.Where("region == @0","City"); }
    
    Refined Count: @venues.Count()
    
      @{ var specials = venues.Children("Special") ; }
    
    Special Count : @specials.Count()
    

    Errors with:

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children'

    Ideas??

  • Karl Kopp 121 posts 227 karma points
    Feb 20, 2012 @ 03:58
    Karl Kopp
    0

    Got it working if I use:

     @{ var specials = venues.Children.Where("nodeTypeAlias == /"Special/"") ; }
    
    Special Count : @specials.Count()
    

     

Please Sign in or register to post replies

Write your reply to:

Draft