Exposing taxonomy field in Sitefinity OData service
Sitefinity OData services and the Client SDK are great, but still lacking some generic functionality and documentation.
A good chance for me to blog a bit on this topic.
Classifications for an item are something I often need.
But they are not so easy to expand.
The $expand is not working, nor does $select, nor selecting it in the webservices.config.
Actually - they work, but all you get is the Id of the taxonomy, so you will have to do a separate query to ask for the details. This gets quite complex (and inefficient) if you have a list of items to resolve for, or a few different types of taxonomies (I.promise() it can be a lot easier using the approach bellow, reducing your callbacks a bit :)).
JustDecompile!
I often use it to see if there is an undocumented functionality (and how things work in general).
With some digging I found that there is a type: "Telerik.Sitefinity.Web.Services.Contracts.TaxonomyRelationResolver".
A brief look at the code confirms it is what we need.
We have everything we need to do this:
Now you will have your taxonomy field exposed in the OData service.
You can use $expand in the query to include it in the results, or a combination of $expand=FieldName($select=Id,Title) to get a faceted result set.
NOTE: This property is read only and you cannot use it for updating the field.
A good chance for me to blog a bit on this topic.
Classifications for an item are something I often need.
But they are not so easy to expand.
The $expand is not working, nor does $select, nor selecting it in the webservices.config.
Actually - they work, but all you get is the Id of the taxonomy, so you will have to do a separate query to ask for the details. This gets quite complex (and inefficient) if you have a list of items to resolve for, or a few different types of taxonomies (I.promise() it can be a lot easier using the approach bellow, reducing your callbacks a bit :)).
JustDecompile!
I often use it to see if there is an undocumented functionality (and how things work in general).
With some digging I found that there is a type: "Telerik.Sitefinity.Web.Services.Contracts.TaxonomyRelationResolver".
A brief look at the code confirms it is what we need.
We have everything we need to do this:
- Go to Advanced Settings => Web Services => [Your Service] => Types => [Your Type] => Property Mappings
- Add new Navigation Property mapping.
- Enter the name for the new property.It should be unique.
- For Resolver Type enter "Telerik.Sitefinity.Web.Services.Contracts.TaxonomyRelationResolver"
- Add a parameter with key "propName" and value the name of taxonomy field (for ex. "Categories")
- Save Changes
Now you will have your taxonomy field exposed in the OData service.
You can use $expand in the query to include it in the results, or a combination of $expand=FieldName($select=Id,Title) to get a faceted result set.
NOTE: This property is read only and you cannot use it for updating the field.