c# - Complex Query using Sitecore 8 content search API -
i trying write linq iterate through list of id's using sitecore content search api throws exception
invalid method call argument type: field - fieldnode - field: supplier_categories_sm - dcp.common.models.shared.categoryitem[]. constant arguments supported.
//the search item class public class eventsupplieritem : basesearchitem { [indexfield("supplier_categories_sm")] public categoryitem[] suppliercategories { get; set; } //maped multilist } //i have wrote custom converter map multilist item public class categoryitem { [sitecoreid] [indexfield("_group")] [typeconverter(typeof(indexfieldidvalueconverter))] public virtual id id { set; get; } [indexfield("name")] public string name { get; set; } }
the code create filter predicate results:
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();
i have tried using .any
instead of .select
still throws same exception sitecore content search linq doesn't support any
or select
in expression. know what's best way deal issue ?
sitecore linq might not able resolve complex query, try following, return expected results:
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();
Comments
Post a Comment