Relations
Lynicon like any CMS allows you to define that content items are related. This is done in the same way as in a relational database, a field contains a reference to the id of another item. When you set a content item property to the type Reference<T>, this has an editor rendered for it which is a drop down list of the titles of all content items whose type is assignable to T. Reference<T> provides some useful properties and methods:
Member | Description |
.IsEmpty | Whether there is any value in the reference |
.Summary() | The summary of the item referred to (as a Summary) |
.GetSummary<T>() | Get the summary of the item referred to indicating what type you want it cast to |
.ItemId | The ItemId of the referenced item (null if nothing referenced) |
.Type | The content type of the referenced item |
.Id | The id (identity) of the referenced item |
Other reference types
Reference<T> inherits from non-generic Reference, which is essentially the same however it is a reference to any content item on the system.
ReferenceList<T> is a special content subtype for selecting multiple references. This is rendered as an enhanced multi-select drop-down in the editor. In code, this is simply a list of Reference<T>
CrossVersionReference<T> allows for references to be made to content items in a different version from the current item. Reference<T> can only reference items in the same version as the current content item, so this is necessary to bypass that. It has a property .Version which returns an ItemVersion for the version in which the referenced item exists. Also it has a property AllowedVersionsOverlay which lets you specify the set of versions which are accessible from the current version via the Mask operation.
Finding all references to an item
You can find all items with references to an item using the call below:
IEnumerable<Summary> Reference.GetReferencesFrom<MyContent>(LyniconSystem sys, object o, string propertyName)
The parameters are as follow:
- sys: The LyniconSystem in which the referring items are to be found
- o: A content item or content container to which the referring items refer
- propertyName: The property on the referring items which is the reference to the referred to item