IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
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 with 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:
You can delete item relations using the following methods:
The following code demonstrates how to create item relations:
var providerName = String.Empty;
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
Type locationType = TypeResolutionService.ResolveType(
"Telerik.Sitefinity.DynamicTypes.Model.DevReach.Location"
);
var location = dynamicModuleManager.GetDataItems(locationType) .FirstOrDefault(t=>t.Status == ContentLifecycleStatus.Master)
Type sessionType = TypeResolutionService.ResolveType(
"Telerik.Sitefinity.DynamicTypes.Model.DevReach.Session"
var session = dynamicModuleManager.GetDataItems(sessionType) .FirstOrDefault(t=>t.Status == ContentLifecycleStatus.Master);
if
(location !=
null
&& session !=
) {
// create a relation to location. Relation will be available only for the current session item state (Master)
session.CreateRelation(location, “Location”);
dynamicModuleManager.SaveChanges();
// on publish, all item's relations are copied from Master to Live availability.
dynamicModuleManager.Lifecycle.Publish(session);
}
In addition, you can delete the relation between the session and the location you created above using the following code:
// delete the relation between the session item and the location
session.DeleteRelation (location, “Location”);
You can retrieve all related child items of particular field using the following methods:
All parent items, of particular item, can be retrieved via the following methods:
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.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important