Sitefinity CMS provides you with an API for managing related items using the RelatedDataExtensions public class. The API consists of extension methods over object items (facilitates the use of the API in widget templates) and over IDataItem for creating and deleting item relations.
IMPORTANT: When using the related data API, you need to work with the master versions of both the related data item and the item, to which you are creating a relation.
You can create content item relations using the following methods:
NOTE: If there is no field with such a name, a relation is still created, even though it will not visible in Sitefinity backend. You can only access the relation via the Related data API, using the same fieldName. The above-described is generally the case when creating relations to content types not supported by the Related data field.
You can delete item relations using the following methods:
The following code demonstrates how to create and delete item relations:
You can retrieve all related child items of particular field using the methods, listed below.
NOTE:You need to enter the accurate corresponding related field name, otherwise the returned result is null.
You can retrieve all parent items of particular item using the methods, listed below.
NOTE:When using the IQueryable interface, be aware that content items do not have a Provider property set, so related data is not returned. The reason is that the Provider property is a complex object and it is not persisted in the database. It is only built when you load the query from the database. When you work with the IQueryable item from the collection, the Provider property is still null. When the final collection is queried, you can use an IEnumerable interface to get single items from the collection.
NOTE: The returned result contains a list with all related data items. The data items are in the same status as the related item, whose child or a parent they are.
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.
This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important