我正在尝试编写一个Linq以使用sitecore内容搜索API遍历ID的列表,但会引发此异常
无效的方法调用参数类型:Field-FieldNode-Field:Supplier_categories_sm-DCP.Common.Models.Shared.CategoryItem []。仅支持常量参数。
//The search item class
public class EventSupplierItem : BaseSearchItem
{
[IndexField("supplier_categories_sm")]
public CategoryItem[] SupplierCategories { get; set; } //maped to multilist
}
//I have wrote custom converter to map the multilist to that item
public class CategoryItem
{
[SitecoreId]
[IndexField("_group")]
[TypeConverter(typeof(IndexFieldIDValueConverter))]
public virtual ID Id { set; get; }
[IndexField("name")]
public string Name { get; set; }
}
创建过滤谓词以获取结果的代码:
var EventCategoryID = new ID(EventSupplierFilters.SupplierCategory);
FilterOR = FilterOR.Or(x => x.SupplierCategories.Select(a => a.Id).Contains(EventCategoryID));
filter = filter.And(FilterOR.Predicate);
results = queryable.Filter(filter.Predicate);
executedResults = results.ToList();
我也尝试使用
.Any
而不是.Select
,但仍会抛出与Sitecore内容搜索linq不支持表达式中的Any
或Select
相同的异常。有谁知道解决这个问题的最好方法是什么?
最佳答案
Sitecore LINQ可能无法解决您的复杂查询,请尝试以下操作,它将返回预期的结果:
var normalizedID = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(EventSupplierFilters.SupplierCategory,true);
FilterOR = FilterOR.Or(x => x["supplier_categories_sm"].Contains(normalizedID));
filter = filter.And(FilterOR.Predicate);
results = queryable.Filter(filter.Predicate);
executedResults = results.ToList();
关于c# - 使用Sitecore 8内容搜索API的复杂查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32305000/