All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statement:
usingUmbraco.Cms.Core.Models;
Constructors
new Relation(int parentId, int childId, IRelationType relationType)
Constructor for creating a new Relation object. The necessary parameters are the Id of the parent item as an int, the Id of the child as an int and the relationType as IRelationType.
new Relation(int parentId, int childId, Guid parentObjectType, Guid childObjectType, IRelationType relationType)
A second constructor exists but it should not be used because it is used to reconstruct a relation from the data source.
Properties
.ChildId
Gets or sets the Child Id of the Relation (Destination)
// Given a `IRelationService` object get Relation by its Id and return ChildIdvar relation =relationService.GetById(1234);returnrelation.ChildId;
.Comment
Gets or sets a comment for the Relation
// Given a `IRelationService` object get Relation by its Id and return Commentvar relation =relationService.GetById(1234);returnrelation.Comment;
.ParentId
Gets or sets the Parent Id of the Relation (Source)
// Given a `IRelationService` object get Relation by its Id and return ParentIdvar relation =relationService.GetById(1234);returnrelation.ParentId;
.RelationType
Gets or sets the RelationType for the Relation
// Given a `IRelationService` object get Relation by its Id and return RelationTypevar relation =relationService.GetById(1234);returnrelation.RelationType;
.RelationTypeId
Gets the Id of the RelationType that this Relation is based on.
// Given a `IRelationService` object get Relation by its Id and return RelationTypeIdvar relation =relationService.GetById(1234);returnrelation.RelationTypeId;