0

We are upgrading from Sitecore 8.2 to Sitecore 10.1.

The method GetDescendantsByTemplateWithFallback exist in Sitecore.ConentSearch.dll Version 2 but this method is missing in Sitecore.ConentSearch.dll Version 8.

 property.GetDescendantsByTemplateWithFallback(Templates.PropertyPageTemplateID);

Is there any alternative to GetDescendantsByTemplateWithFallback that can be used in Sitecore 10.1?

2
  • Does this help you? support.sitecore.com/… Commented Jan 25, 2022 at 6:52
  • @Gaurav agarwal. Thanks for the link but this is something different because the link talks about resolving the error. In my case i am looking for alternative to GetDescendantsByTemplateWithFallback method in Sitecore 10.1 because this method doesn’t exist. Commented Jan 25, 2022 at 9:06

2 Answers 2

2

LanguageFallbackDataService was marked as obsolete in 9.3.

No replacement was provided in obsolete info.

This kb article describes a bug which is strictly related to GetDescendantsByTemplateWithFallback extension method

Replacement

I tracked how previous usages in Sitecore were updated and I found one. Here is a code example:

before

result = property.GetDescendantsByTemplateWithFallback(Templates.PropertyPageTemplateID)

after

var templateID = new TemplateID(ID.Parse(Templates.PropertyPageTemplateID));
result = property.Axes.GetDescendants().Where(i => i.TemplateID == templateID)

You can create your own extension method and put this implementation there.

Hope it helps.

1

The following extension method would be equivalent to a deprecated search utility.

public static IEnumerable<Item> GetDescendantsByTemplateWithFallback(this Item rootItem, string templateID) {
  var items = new List<Item>();
  ID templateId = new ID(templateID);
  var index = ContentSearchManager.GetIndex(new SitecoreIndexableItem(rootItem));
  using (var context = index.CreateSearchContext()) {
    items = context.GetQueryable<SearchResultItem>()
                .Where(x => x.TemplateId == templateId &&
                            x.Path.StartsWith(rootItem.Paths.FullPath))
                .Select(i => i.GetItem())
                .ToList();
  }
  return items;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.