Copied to clipboard

Flag this post as spam?

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


  • Manish 373 posts 932 karma points
    Jul 06, 2016 @ 08:26
    Manish
    0

    Where condition in desendents

    Hi

    I just wanted to put a where clause after Descendants

    var x = CurrentPage.AncestorOrSelf(1).Descendants(docType).ToList().Where(x => x.GetProperty("property").Value == "matchingtext");
    

    How can i achieve this

    Manish

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 06, 2016 @ 08:32
    Dirk De Grave
    1

    var x = CurrentPage.AncestorOrSelf(1).Descendants(docType).Where(x => x.GetPropertyValue

    On a sidenode... you may run into a serious performance issue if you're using Descendants() on a top level node, as it will iterate every single node in your node structure... Image if you'd have 10000 nodes

    Don't know the context, so can't suggest alternatives atm.

    -Dirk

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Jul 06, 2016 @ 09:09
    Lee Kelleher
    103

    In terms of performance, here are some alternatives... YMMV

    XPath, baby!

    var xpath = string.Format("//{0}[@isDoc and {1} = '{2}']", "DocTypeAlias", "propertyAlias", "matchingtext");
    var items = Umbraco.TypedContentAtXPath(xpath);
    

    XPath is super fast, but gets a bad rap because no one really likes XSLT anymore... and no one knows what the performance will be like once NuCache is the default cache in Umbraco v8. But while we've still got an XML cache, XPath is best IMHO.

    Examine, baby!

    var query = ExamineManager.Instance.CreateSearchCriteria()
        .NodeTypeAlias("DocTypeAlias")
        .And()
        .Field("propertyAlias", "matchingtext")
        .Compile();
    
    var results = Umbraco.TypedSearch(query);
    

    Also super fast, but there's a lot more configs/switches to play around with. This may or may not be a good thing for you.

    If you want to know more about Examine, here are a couple of great posts:


    Just to note, there's nothing wrong with using Linq queries - I use them all the time - it's a case of knowing when to use them and if there are better tools for the job. As Dirk says, using Descendants() from the root node will become a performance nightmare.

    Cheers,
    - Lee

  • Manish 373 posts 932 karma points
    Jul 11, 2016 @ 06:11
    Manish
    0

    Thanks Lee Kelleher

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies