Sitecore 9.3

What I have till now:

I am able to filter items based on a template using the search context.

var unversionedImageTemplateId = ID.Parse(Constants.UnversionedImageTemplateId);
var jpegTemplateId = ID.Parse(Constants.Jpeg);

var results = context.GetQueryable<SearchResultItem>()
  .Where(x => x.TemplateId == unversionedImageTemplateId || x.TemplateId == jpegTemplateId)

What I am trying to do:

I want to put one more condition based upon the value of a field, a check box.

What I tried:

  1. I tried using .Where after the code I have.
  2. I tried applying the condition using && in the same Where command.

But I always get the following error.

Exception: System.NotSupportedException
Message: The method 'get_Item' is not supported.
Source: Sitecore.ContentSearch.Linq

Any idea how to move ahead with it?

1 Answer 1


You should use Predicate builder to build your query. You will have something like:

      var predicate = PredicateBuilder.True<SearchResultItem>();
      predicate = predicate.And<SearchResultItem>(i => i.TemplateId == [Template ID]);
     #Get items under specific node or Items from specific location in Sitecore –
     predicate = predicate.And<SearchResultItem>(i => i.Paths.Contains([Location Item ID]));
     #Get items for context language only  –
     predicate = predicate.And<SearchResultItem>(item => item.Language == Context.Language.Name);
     # get items which have a field value
     predicate = predicate.And<SearchResultItem>(item => item["fieldname"] == "Sitecore")
  • Thanks. I missed the predicates. Commented Oct 8, 2020 at 17:07

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.