Copied to clipboard

Flag this post as spam?

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


  • Tony Bolton 83 posts 109 karma points
    Feb 28, 2012 @ 15:53
    Tony Bolton
    0

    Need help with weird Where clause selection

    Hi all,

    This has been doing my head in so I hope someone can help.

    Here's the code in question - dead simple:

      var rootNodeVal int.Parse(Parameter.RootNode);
      var businessId Model.Id;
      
      var rootNode Library.NodeById(rootNodeVal);
      Dictionary<string,stringdic new Dictionary<string,string>();
      
      dic.Add("ModelId",Model.Id.ToString());

      foreach(var node in rootNode.Descendants("Voucher").Where("Business == businessId"))
      {
       @node.Business.GetType()
      }


    Now there's a couple of lines in there where I've been experimenting - namely the dictionary and the addition of the current page ID to it.

    All it needs to do is select documents of type Voucher from anything below what I specify as the root node (rootNode).

    In the Document type Voucher, there's a content picker to select a node, called Business.

    Looking in umbraco.config I can see it's stored the value correctly ie.

    <Business>1234</Business>

    And if I iterate through the nodes without the where clause, it is finding these Voucher documents fine and dumping out the selected Business node ID.  If I dump the type, it's a String.

    So - why is it when I use the where clause ie. Where("Business == businessId"), or Where("Business == ModelId",dic), it is not finding the appropriate nodes when I know they're there.

    I've tried everything - casting to int, strongly typing the variables etc - nothing works.  I'm proper stuck so any help much appreciated.

    Cheers!
    Tony

  • Tony Bolton 83 posts 109 karma points
    Feb 28, 2012 @ 16:01
    Tony Bolton
    0

    It's 4.7.1.1 btw. :)

  • Tony Bolton 83 posts 109 karma points
    Feb 28, 2012 @ 16:11
    Tony Bolton
    0

    Some more info - here is the result of the iteration with the Where clause set to "Business != null" :

    This document is node id 4637

    Voucher ID 6680 property Business is set to , of type System.String

    Voucher ID 6683 property Business is set to 4637, of type System.String


    So there filter is obviously working, but not if I directly compare to the document (Model) node id, which is 4637.  As you can see, document 6683 has the business set to node id 4637 - so with the filter I mentioned above applied it should list it - but it doesn't.

     

  • Tony Bolton 83 posts 109 karma points
    Feb 28, 2012 @ 16:22
    Tony Bolton
    0

    Gah!  Typical - perserverance always pays off.

    Turned out it was my declaration of the dictionary - string,string didn't work - it was string,object that sorted it.  Setting the id in the dict via ToString() did the trick. Still not quite sure why string,string didn't work though so if anyone could make me any wiser I'd be grateful. 

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Feb 28, 2012 @ 21:35
    Jeroen Breuer
    1

    Glad you got it fixed, but be careful about using .where too much. More info in this topic: http://our.umbraco.org/forum/developers/razor/28479-Razor-menu-performance-(v4)

    Jeroen

  • Tony Bolton 83 posts 109 karma points
    Feb 28, 2012 @ 21:47
    Tony Bolton
    0

    Cheers Jeroen - that's a really interesting post and might well prove useful later.  I'm wondering if the same kind of performance impact is felt if you called a delegate to filter the nodeset instead?  I use that alot in parts, especially for filtering using more complex checks.  Might have to do some tests :/

Please Sign in or register to post replies

Write your reply to:

Draft