Sitecore 9.3
I am trying to use 'predicates' to get a subset of data.
When I have the code snippet as:
using (var contextA = selectedIndex.CreateSearchContext())
{
var predicate = PredicateBuilder.True<SearchResultItem>();
predicate = predicate.And<SearchResultItem>(i => i.TemplateId == unversionedImageTemplateId || i.TemplateId == jpegTemplateId);
var queryable = contextA.GetQueryable<SearchResultItem>();
var resultsList = queryable.Where(predicate).Select(i => i.GetItem());
}
But when I put another condition on the basis of the path in addition to the above condition, I do not get any item in result. I have checked in Sitecore that I have multiple such items.
using (var contextA = selectedIndex.CreateSearchContext())
{
var predicate = PredicateBuilder.True<SearchResultItem>();
predicate = predicate.And<SearchResultItem>(i => i.TemplateId == unversionedImageTemplateId || i.TemplateId == jpegTemplateId);
predicate = predicate.And<SearchResultItem>(i => i.Paths.Contains(mediaLibraryId));
var queryable = contextA.GetQueryable<SearchResultItem>();
var resultsList = queryable.Where(predicate).Select(i => i.GetItem());
}
I am trying to add more condition on the basis of a checkbox selected or not. Please help me to understand where I am going wrong.