Customize association types for Releated Entities
Customizing Related Entities association type does’t seem to be covered very well in Episerver documentation. In this post, I’ll quickly show you how easily this can be achieved.
Define custom types for Related Entities
- Create a new
InitializationModuleclass. - Use Episerver
ServiceLocatorto create an instace ofAssociationGroupDefinition. - Add your custom association type via
Addmethod. (Note:Addmethod perofrms type name existence check, therefore you won’t accidentally add duplicate type.)
- Build solution, log in to CMS and navigate to Product’s Related Entities, you’ll see other types than the out-of-the-box Default type.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class AssociationTypeInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
var associationTypeRepository = context.Locate.Advanced.GetInstance<GroupDefinitionRepository<AssociationGroupDefinition>>();
associationTypeRepository.Add(new AssociationGroupDefinition() { Name = "cross-selling" });
associationTypeRepository.Add(new AssociationGroupDefinition() { Name = "upselling" });
}
public void Uninitialize(InitializationEngine context){}
}
Querying association types
Association types are stored in tblBigTable under the hood. You can use the query below to verify how many types defined in the system.
1
2
3
4
SELECT TOP 10 *
FROM tblBigTable
WHERE storename =
'EPiServer.Commerce.Catalog.Linking.AssociationGroupDefinition'
Happy Coding! 😇
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.