Efficiently querying for content items associated to a specific term in Orchard CMS 1.7.2

StackOverflow https://stackoverflow.com//questions/21047070

  •  21-12-2019
  •  | 
  •  

Pregunta

I've got a content type with a TaxonomyField, and a number of content items with various terms associated to them. Given a term (not a term ID, but the actual textual term), what's the most efficient way to query for all content items associated with that term?

¿Fue útil?

Solución

You would need to get the Term first, using the Slug (I assume that is what you mean by Term Text). Use the taxonomy service for this.

And then you can use this query

_orchardServices.ContentManager
                        .Query("CONTENT TYPE")
                        .Join<TermsPartRecord>()
                        .Where<TermsPartRecord>(x => x.Terms.Any(y => y.TermRecord.Id == RECOVERED TERM.Id)
                        .List()

You can also use WithQueryHints(new QueryHints().ExpandParts()), if you know which parts of your content items you would need (this will eagerly load them).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top