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
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

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).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top