Skip to content
Simple way of adding two-way relationships between content in Episerver
C#
Branch: cms10
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
Epinova.Associations.sln
LICENSE
appveyor.yml
readme.md

readme.md

Epinova.Associations

Flexible, easy to use two way relationship between content nodes.

  • Supports ContentReference, IList<ContentReference> and ContentArea as both source and target for an association, and you can use differerent types in each end of the relationship.
  • Matches association sources and targets on property name (meaning you can have multiple different associations per content type)
  • To use, let your content type class implement IAssociationContent, and simply add [ContentAssociation] to the properties you want to use for associations.
    • Supports IContent, meaning association properties can be added to both pages, blocks or media types; anything that implements IReadOnly and IContent.
    • To limit what content types go where, use [AllowedTypes]; this can vary on each end of the relationships
  • Associations are saved to the otherside of the relationship on publishing

Examples

[ContentType(GUID = "...")]
public class EmployeePage : BasePageData, IAssociationContent
{
    [ContentAssociation]
    public virtual ContentArea EmployeeDocuments { get; set; }
	
    [ContentAssociation]
    public virtual ContentArea Author { get; set; }
}

[ContentType(GUID = "...")]
public class DocumentPage : BasePageData, IAssociationContent
{
    [ContentAssociation]
    public virtual IList<ContentReference> EmployeeDocuments { get; set; }
			
    [ContentAssociation]
    public virtual ContentReference Author { get; set; }
}

Here, whatever you add into the EmployeeDocuments will be reflected to the other side of the relationship when you publish your content. Note that the property has the same name on both content types.

You can even use [AllowedTypes] in combination with this to restrict what types go where, like so:

[ContentType(GUID = "...")]
public class EmployeePage : BasePageData, IAssociationContent
{
    [ContentAssociation]
    [AllowedTypes(typeof(DocumentPage))]
    public virtual ContentArea EmployeeDocuments { get; set; }
	
    [ContentAssociation]
    [AllowedTypes(typeof(DocumentPage))]
    public virtual ContentArea Author { get; set; }
}

[ContentType(GUID = "...")]        
public class DocumentPage : BasePageData, IAssociationContent
{
    [ContentAssociation]
    [AllowedTypes(typeof(EmployeePage))]
    public virtual IList<ContentReference> EmployeeDocuments { get; set; }
	
    [ContentAssociation]
    [AllowedTypes(typeof(EmployeePage))]
    public virtual ContentReference Author { get; set; }
}
You can’t perform that action at this time.