Back

BLOG • DIGITAL INSIGHTS

Exposing Taxonomy Fields in Sitefinity OData Service

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 CMS

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.

The Problem

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.

The Discovery - TaxonomyRelationResolver

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.

How to Set It Up

  1. Go to Advanced Settings - Web Services - [Your Service] - Types - [Your Type] - Property Mappings
  2. Click Add new Navigation Property mapping
  3. Enter a unique name for the new property
  4. For Resolver Type, enter Telerik.Sitefinity.Web.Services.Contracts.TaxonomyRelationResolver
  5. Add a parameter with key propName and value set to the name of your taxonomy field (for example, Categories)
  6. Save Changes

Using the Exposed Field

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.

Read More

Explore more insights and case studies from our team.