3

I'm trying to do this:

queryable.Where(i => i["_template"] == templateId);

Where templateId is a Guid string, but it doesn't work. However, this does work:

queryable.Where(i => i["_templatename"] == templatename);

What do I need to do in order to filter by ID?

P.S. I realise I can use the typed template ID property, but I need the field name to be dynamic.

  • Could you try to execute your query in Luke? Link to application getopt.org/luke – Andrei Paliakou Nov 15 '17 at 17:04
  • Also _template field in index stores value like c6576836910c4a3dba03c277dbd3b827 – Andrei Paliakou Nov 15 '17 at 17:09
6

This probably isn't working because the value stored inside i["_template"] is the parsed GUID value from the index.

Try using:

Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(templateId)

This will convert any GUID to the format which is stored inside the search index.

|improve this answer|||||
0

Can't you do something mode along the lines of:

var predicate = PredicateBuilder.True<T>();

predicate = predicate.Where(i => i.TemplateId = templateId);

var results = queryable.Where(predicate);

There is more info on this here: https://doc.sitecore.net/sitecore%20experience%20platform/developing/developing%20with%20sitecore/search%20and%20item%20buckets/linq%20to%20sitecore

|improve this answer|||||
  • as per my question, I realise I can do this, but I need the property name to be dynamic. i.e. it's not just the template id I might want to search on, it might be a custom droptree field – David Masters Nov 15 '17 at 18:19
  • Sorry David I missed what you meant by that. Looks like you have a solution. – Adam Seabridge Nov 16 '17 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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