DocumentQuery TreeProvider.SelectNodes() and multiple document types

Stefan Lorenz asked on May 21, 2014 10:39

Hi,

the title says it all, I want to query the document tree with the new DocumentQuery classes but select multiple document types:

var tree = new TreeProvider();
var docs = tree.SelectNodes("CMS.MenuItem") // <= This works
var docs = tree.SelectNodes("CMS.MenuItem;CMS.File"); // <= This doesn't work

With the old Dataset approach this is possible, but I really would like to use the new DocumentQuery way, it's so incredible fun to work with. I browsed the API but didn't find a way to achieve this. Any idea?

Correct Answer

Jakub Oravec answered on May 22, 2014 00:53

Hi Stefan,

try method SelectNodes() without parameter. It returns MultiDocumentQuery so you can work with more document types at once.

var tree = new TreeProvider();
var docs = tree.SelectNodes()
              .Type("CMS.Article", q =>
                  q.Columns("ArticleName")
                  )
              .Type("CMS.News", q =>
                  q.Columns("NewsTitle")
                  )
              .Path("/News", PathTypeEnum.Children)
              .Path("/Examples", PathTypeEnum.Children)
              .Columns("DocumentCulture, DocumentName")
              .OrderBy("DocumentName")
              .OnSite("CorporateSite")
              .Culture("cs-cz")
              .CombineWithDefaultCulture();
5 votesVote for this answer Unmark Correct answer

Recent Answers


Stefan Lorenz answered on May 22, 2014 02:01

Thanks a lot!

0 votesVote for this answer Mark as a Correct answer

Jürgen Gutsch answered on June 19, 2014 08:25

Hi,

Thanks for that code snippet. it runs very fine :) But i can't access the document properties in this way:

var nodes = _provider.SelectNodes()
                .Type("my.ArchivNews")
                .Type("my.News")
                .Path(_settings.CmsRootNode, PathTypeEnum.Children)
                .Culture("de-CH")
                .NestingLevel(5);
foreach (var treenode in nodes)
{
  var headline = ValidationHelper.GetString(treenode.GetValue("Headline"), String.Empty);
  // headline is always null
}

The result is allays null. If I select a single node (with TreeProvide.SelectSingleNode()) inside the loop for each node, I'm able to read the custom properties from the selected nod.

How can I get the custom properties with TreeProvide.SelectNodes?

0 votesVote for this answer Mark as a Correct answer

Stefan Lorenz answered on June 19, 2014 08:42

I guess you'll need to add the columns you want to the .Type() method like Jakub shows, e.g.

.Type("my.ArchivNews", q => q.Columns("Headline"))
2 votesVote for this answer Mark as a Correct answer

Jürgen Gutsch answered on June 19, 2014 08:52

Hi Stefan, works great. Many Thanks :) Cheers, Juergen

0 votesVote for this answer Mark as a Correct answer

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