HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback

Related entries are represented by the EPiServer.Commerce.Catalog.Linking.Association class and administered using the EPiServer.Commerce.Catalog.Linking.IAssociationRepository service.

The Target property of the Association contains the ContentReference of the related entry. The class also has a EPiServer.Commerce.Catalog.Linking.AssociationGroup (defined by its Nameproperty) describing a grouping of several related entries, and an EPiServer.Commerce.Catalog.Linking.AssociationType (defined by its Id property) describing the type of the relation.

These three properties, together with the Source ContentReference (the item that has the related item) together uniquely define a related item, that is, there can not be two Association objects with all these values equal.

## Get related entries for an entry

By calling the GetAssociations method of IAssociationRepository with the ContentReference of an entry, you get all the related entries. The related entries are returned as Association instances.

### Add a related entry to an entry

Use the UpdateAssociations method or UpdateAssociation extension method of IAssocitionRepository to add new Association objects to describe a new relation to an entry. The new entry must have a Target ContentReference, a Source ContentReference, an AssociationGroup and a AssociationType. The AssociationGroup class has a DefaultName property you can use as name of the group, and the AssociationType class has a DefaultId property you can use as id of the type.

### Remove a related entry from an entry

To remove a related item, call the RemoveAssociations method or the RemoveAssociation extension method of IAssociationRepository with an Association object matching an existing related item. You can construct a matching object, or use GetAssociations to get the existing Associations, to filter out the object you want to remove and pass it to RemoveAssociation.

### Set up available association groups

When marketers are editing related entries, they can select the association type from a list of association groups. Developers can configure the groups available in the drop-down so they match what is used in the site implementation.

Populate the list by adding the code as illustrated in the example below. Call that from the Initialize method of your InitializationModule.