Exclude all nested children of unpublished nodes in a QueryProvider

James Mosquito asked on March 31, 2021 22:31

Hi, given the following query as an example:

var menuItems = MenuItemProvider
    .GetMenuItems()
    .Path(path, PathTypeEnum.Children)
    .NestingLevel(maxDepth)
    .LatestVersion(_latestVersionEnabled)
    .Published(!_latestVersionEnabled)
    .OnSite(SiteContext.CurrentSiteName)
    .Culture(_cultureName)
    .CombineWithDefaultCulture()
    .OrderByAscending("NodeOrder");

How would I exclude all descendant nodes in cases where a parent is unpublished. There can be multiple levels and the unpublished parent node might be in any of those.

Recent Answers


David te Kloese answered on April 1, 2021 10:27

Since the child nodes are published and this can be on any level for any number of items I think it's easier to just work with the result set. And recursively go over each level, and remove any Node where the Parent NodeID is not part of the result set.

I assume this doesn't change to often, so adding caching and appropriate dependencies should suffice.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.