BLOG • DIGITAL INSIGHTS
Sitefinity OData services return only taxonomy IDs by default, requiring extra queries to resolve their details. This post shows how to use TaxonomyRelationResolver and Navigation Property mappings to expose taxonomy fields directly in your OData service, enabling $expand queries to return classification data in a single call.
Sitefinity OData services and the Client SDK are great, but still lacking some generic functionality and documentation. A good chance to blog a bit on this topic.
Classifications (taxonomy fields) for content items are something I often need to expose - but they are not straightforward to expand.
$expand does not work out of the box, nor does $select, nor selecting them in webservices.config. Well, technically they work - but all you get back is the ID of the taxonomy, which means you have to make a separate query for the details. This gets complex and inefficient quickly if you have a list of items to resolve, or multiple taxonomy types. I promise it can be a lot easier with the approach below, cutting down your callbacks significantly.
I often use JustDecompile to find undocumented functionality and understand how things work internally. After some digging I found the type Telerik.Sitefinity.Web.Services.Contracts.TaxonomyRelationResolver - a brief look at the code confirmed it is exactly what we need.
Telerik.Sitefinity.Web.Services.Contracts.TaxonomyRelationResolverpropName and value set to the name of your taxonomy field (for example, Categories)Your taxonomy field is now exposed in the OData service. You can use $expand in the query to include it in results, or combine it with a select to get a faceted result set:
$expand=FieldName($select=Id,Title)
Note: This property is read-only. It cannot be used to update the taxonomy field value.
Explore more insights and case studies from our team.