API Reference: KeyAttribute Class

The KeyAttribute can be applied to content model classes and properties. The attribute specifies the unique key of the object for data storage. If KeyAttribute is not specified, the class or property identifier will be used as the unique key.

All content type definitions in the Redakt system must have a different unique key, to be able to correctly retrieve models from the database. If duplicate keys exist, Redakt will throw a configuration exception on system startup. Particularly, this will happen if you have multiple content model classes with the same name in different namespaces. In that case, you will need to set unique keys using the KeyAttribute.

Usage

Decorate the model class or property with the KeyAttribute. Pass the key in the attribute constructor. The key must be an alphanumeric identifier without spaces or special characters. For content model classes, the key must be unique across all content models in the solution. For properties, the key must be unique across all properties of that class, including inherited properties from base classes.

Example

[Key("CampaignContentPage")]
public class ContentPage: IContentType
{
    [Key("SeoContent")]
    public SeoContent Seo { get; set; }

    // Key will be "SecondParagraph" by convention
    public ParagraphContent SecondParagraph { get; set; }
}