Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1474 posts 3431 karma points c-trib
    Feb 06, 2012 @ 12:00
    Simon Dingley
    0

    Excluding Document Types in Where Clause

    I have the following simplified example that I am trying to get working. I want to implement it like this to make it more maintainable as the list of exluded document types will grow to the extent that it doesn't seem right to have a long list of 'or' checks in the where clause if it can be helped.

            var excludedDoctypes = new[] { "StaffMember", "StaffCategory" };
    
            var items = node.Children.Where("!excludedDoctypes.Contains(NodeTypeAlias) && Visible").Where("Level <= 4");

    Any ideas why this does not have the desired affect or am I just missing something really obvious?

    TIA

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 06, 2012 @ 12:42
    Jeroen Breuer
    0

    Hmm perhaps an XPath is easier here. Here is an example where you can say which doc types are allowed:http://our.umbraco.org/forum/developers/api-questions/18933-Query-multiple-websites?p=2#comment74400. Probably easy to change so you can say which ones aren't allowed.

    I use it for DAMP too: http://damp.codeplex.com/SourceControl/changeset/view/81602#1765791

    Jeroen

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 06, 2012 @ 14:46
    Dan Diplo
    0

    I don't think Contains has been implemented in Umbraco's "dynamic" implementation of LINQ (ie. where the query is a string), hence the reason it won't work.

    However, this should work:

     var items = CurrentModel.GetChildrenAsList.Items.Where(x => !excludedDoctypes.Contains(x.NodeTypeAlias));

    The reason is that CurrentModel is a strongly typed (DynamicNode) version of "Model" and hence you can perform standard LINQ to Objects queries.

  • Rodion Novoselov 694 posts 859 karma points
    Feb 07, 2012 @ 13:45
    Rodion Novoselov
    0

    Yet another possible way I suppose:

    var sel = _s => string.Format("NodeTypeAlias != '{0}'",  _s);
    var qry = "Visible && " + string.Join( " && ",  excludedDoctypes.Select(sel));
    var items = node.Children.Where(qry);

     

Please Sign in or register to post replies

Write your reply to:

Draft