Press Ctrl / CMD + C to copy this to your clipboard.

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

My tree looks like this:

I want to get all children of Multifamily and Commercial Mixed Use sorted by name. My code is only returning Children from Multifamily. I know why (the First), but I don't know how to fix it.

First

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var root = Model.Content.Site(); var selection = root.Children.First(x => (x.Name == "Multifamily" || x.Name == "Commercial Mixed Use")).Children.Where(x => x.IsVisible()).Where(x => x.GetPropertyValue<Boolean>("communityDetailIsHidden") == false).Where(x => x.GetPropertyValue<String>("communityDetailStatus").ToString().ToLower() != "past community"); }

This is on a Partial Template if that makes any difference.

Hi bh,

There is only a minor change you should need to make:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var root = Model.Content.Site(); var selection = root.Children .Where(x => (x.Name == "Multifamily" || x.Name == "Commercial Mixed Use")) .Children.Where(x => x.IsVisible()) .Where(x => x.GetPropertyValue<Boolean>("communityDetailIsHidden") == false) .Where(x => x.GetPropertyValue<String>("communityDetailStatus").ToString().ToLower() != "past community"); }

You just needed to change .First to .Where

If you were meaning to return only 1 node then at the end add .FirstOrDefault() like so:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var root = Model.Content.Site(); var selection = root.Children .Where(x => (x.Name == "Multifamily" || x.Name == "Commercial Mixed Use")) .Children.Where(x => x.IsVisible()) .Where(x => x.GetPropertyValue<Boolean>("communityDetailIsHidden") == false) .Where(x => x.GetPropertyValue<String>("communityDetailStatus").ToString().ToLower() != "past community").FirstOrDefault(); }

@LouisJackson-Rees thanks for the thought. Unfortunately using Where in place of First won't let me do the .Children.Where that comes next.

Where

.Children.Where

Here's the exact error. 'Umbraco.Web.PublishedContentExtensions.Children

Aplologies, try .Select

@LouisJackson-Rees thanks. But same error. Umbraco.Web.PublishedContentExtensions.Children

Umbraco.Web.PublishedContentExtensions.Children

GOT IT! I did two queries and unioned 'em. @LouisJackson-Rees thanks for your input!

var root = Model.Content.Site(); var selection = root.Children.First(x => x.Name == "Multifamily") .Children.Where(x => x.IsVisible()).Where(x => x.GetPropertyValue<Boolean>("communityDetailIsHidden") == false) .Where(x => x.GetPropertyValue<String>("communityDetailStatus").ToString().ToLower() != "past community"); var selection2 = root.Children.First(x => x.Name == "Commercial Mixed Use") .Children.Where(x => x.IsVisible()).Where(x => x.GetPropertyValue<Boolean>("communityDetailIsHidden") == false) .Where(x => x.GetPropertyValue<String>("communityDetailStatus").ToString().ToLower() != "past community"); selection = selection.Union(selection2); selection = selection.OrderBy(x => x.GetPropertyValue("communityDetailCommunityName"));

is working on a reply...

Write your reply to:

Upload image

Image will be uploaded when post is submitted

## Node Query ?

My tree looks like this:

I want to get all children of Multifamily and Commercial Mixed Use sorted by name. My code is only returning Children from Multifamily. I know why (the

`First`

), but I don't know how to fix it.This is on a Partial Template if that makes any difference.

Hi bh,

There is only a minor change you should need to make:

You just needed to change .First to .Where

If you were meaning to return only 1 node then at the end add .FirstOrDefault() like so:

@LouisJackson-Rees thanks for the thought. Unfortunately using

`Where`

in place of`First`

won't let me do the`.Children.Where`

that comes next.Here's the exact error. 'Umbraco.Web.PublishedContentExtensions.Children

Aplologies, try .Select

@LouisJackson-Rees thanks. But same error.

`Umbraco.Web.PublishedContentExtensions.Children`

GOT IT! I did two queries and unioned 'em. @LouisJackson-Rees thanks for your input!

is working on a reply...