Copied to clipboard

Flag this post as spam?

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


  • Morten Jensen 41 posts 104 karma points
    Jul 16, 2013 @ 10:11
    Morten Jensen
    0

    DocumentTypeId in Where not working?

    Hello

    I am trying to get a set of nodes based on thier DocumentTypeId (from at Macro contentTypeMultiple list). But the following code do not work:

     

    nodes = root.DescendantsOrSelf().Where("DocumentTypeId == 1000");

     

    but

     

    nodes = root.DescendantsOrSelf().Where(x => x.DocumentTypeId == 1000); 

    works?

    The reason why i am not using the last one is that i want to generate a flexible query, which can contain multiple DocumentTypeIds with OR. Ex:

     

    nodes = root.DescendantsOrSelf().Where("DocumentTypeId == 1000 || DocumentTypeId == 1001");

     

    Is there any reason that the first Where query dont work and the second does?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jul 18, 2013 @ 14:25
    Jeavon Leopold
    0

    Hi,

    I think that this is because when you pass the string parameter to a .Where method it uses a dynamic expression parser and the fixed properties that are supported to not include DocumentTypeId (i'm 100% clear on this though). Anyway, you can do what you need with the lambda expression:

    var nodes = root.DescendantsOrSelf().Where(x => x.DocumentTypeId == 1000 || x.DocumentTypeId == 1001);

     Thanks,

    Jeavon

  • Funka! 398 posts 661 karma points
    Jul 18, 2013 @ 23:47
    Funka!
    1

    I wonder if Contains would work too here? You could eliminate need for any string generation. For example: (warning not tested!)

    int[] ids = new int[] { 1000, 1001, 1002, 1003 }; // or any IEnumerable<int>
    var nodes = root.DescendantsOrSelf().Where(x => ids.Contains(x.DocumentTypeId));

    Good luck!

Please Sign in or register to post replies

Write your reply to:

Draft