Copied to clipboard

Flag this post as spam?

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


  • Vincent Baaij 95 posts 344 karma points c-trib
    May 21, 2013 @ 17:20
    Vincent Baaij
    0

    DynamicNodeList .Where() on more than one field

    Hi,

    I'm trying to filter a DynamicNodeList on more than one field, but failing misserably. Is it possible to do in one .Where clause? This is what I've come up with so far:

    items = root.Descendants("alias");
    var values = new Dictionary<string,object>();
    values.Add("fromA", 0);   
    values.Add("toA", 100);   
    values.Add("fromB", 0);   
    values.Add("toB", 100);   
    string s="";
    s = "(priceA >= fromA && priceA <= toA) || (priceB >= fromB && priceB <= toB)";

    DynamicNodeList possibleNodes = items.Where(s, values);

    A solution would be to seperate the conditions and join the results from the 2 Where filters, ut as far as I know, you can't join DynamicNodeLists.

    Any help appreciated.

     

     

  • Vincent Baaij 95 posts 344 karma points c-trib
    May 22, 2013 @ 10:47
    Vincent Baaij
    100

    Solved it like this (saved for reference)

     

    List<DynamicNode> nl = items.Items;
     
    var possibleNodes = nl.Where(x => x.GetProperty<int>("fromA") >= int.Parse(Request["priceA"]) && x.GetProperty<int>("fromB") <= int.Parse(Request["priceA"]) ||
                           x.GetProperty<int>("fromB") >= int.Parse(Request["priceB"]) && x.GetProperty<int>("fromB") <= int.Parse(Request["priceB"]));
       
     
Please Sign in or register to post replies

Write your reply to:

Draft