Я пытаюсь получить Children
объекта Icontent
.
IContent filialsParent = cs.GetById(filialParrentId);
if (filialsParent != null)
{
IContentService contentService = Umbraco.Core.Composing.Current.Services.ContentService;
bool hasChildren = contentService.HasChildren(filialsParent.Id);
long totalChildren;
IEnumerable<IContent> children = contentService.GetPagedChildren(filialsParent.Id, 1, 100, out totalChildren);
foreach (var child in children)
{
context.WriteLine(string.Format("child: {0}", child.Name));
}
context.WriteLine(string.Format("Children found:({0}) in: {1}", children.Count(), filialParrentId));
}
Если я отлаживаю код, я получаю следующее.
Мой long totalChildren
будет 1 после того, как строка contentService.GetPagedChildren(filialsParent.Id, 1, 100, out totalChildren);
запустится.
Мой IEnumerable<IContent> children
нулевой, и по этой причине (конечно) мой children.Count()
0
К сожалению, filialsParent
не содержит функции .children()
, как я надеялся.
Есть ли способ получить детей моего filialsParent
, и да, у него есть дети, которые опубликованы.
У меня точно такая же проблема. В целях тестирования я удалил все, только самое необходимое.
==> умбрако 8.0.2
Убедитесь, что у вас есть родитель и несколько детей.
// For testing purposes hardcode your parent Id
var contentId = [ID];
// SET for returning total records
long totalChildren;
// int id ==> You even could hardcode your first param (contentID in here)
// long pageIndex ==> SET your index to 0 ==> first indexpage starts at 0 and not 1 ==> if you set this to 1 and the Pagesize = 100 and you have only 99 childeren you wil wil get null because we are requesting the second page
// int pageSize ==> We need max 10 childeren
// out long totalChildren
// IQuery<IContent> filter = null ==> not used
// Ordering ordering = null ==> not used
IEnumerable<IContent> children = Services.ContentService.GetPagedChildren(contentId, 0, 10, out totalChildren);