Using EPiServer Typed Models

Top  Previous  Next

As described in the sections Mapping Page Types to Topic Types and Mapping EPiServer Pages to Topics, the TMCore EPiServer Module requires two properties to be defined on the Page Type for pages that are to be automatically mapped to topics in the TMCore database. Those properties can be manually added to a Page Type as described in that section. However, if you are developing Page Types using the new strongly-typed content model facility of CMS7, then there is a more convenient way to define these properties in code.

If you decide to take this approach we recommend that you make use of the NP_TM_TopicType and NP_TM_TopicSIPageProperty configuration properties to change the property names to names that also work as C# property names. The default names (nptopictype and topicGuid) are valid C# identifiers, but convention requires that property names be in upper camel-case, so we recommend using TopicType and TopicGuid instead.

You can then add the required properties into the model for the page as shown in the code below:

    public class MyPage : PageData

    {

        // Page properties go here

 

        // TMCore EPiServer Module Page Type Mapping

        [Editable(false)]

        public virtual string TopicType { get; set; }

 

        // TMCore EPiServer Module Page Topic Mapping

        [Editable(false)]

        public virtual string TopicGuid { get; set; }

 

        public override void SetDefaultValues(ContentType contentType)

        {

            base.SetDefaultValues(contentType);

            // Provide a fixed default value for the TopicType property

            this.TopicType = "http://www.example.com/psi/types/myPageType";

        }

    }

 

Note that the SetDefaultValues(ContentType) method is used to provide a default for the TopicType property - this ensures that all pages of this Page Type will be represented by a topic in TMCore with a type that is identified by the subject identifier http://www.example.com/psi/types/myPageType. Also note that both properties are set as read-only using the [Editable(false)] attribute - this will ensure that editors cannot change the values of these properties but does not prevent them from being changed in code.

If you are creating a large number of PageData classes that map to topics, you may want to consider creating a base class that has these two core properties defined on it. However, each class should have its own override of SetDefaultValues or you should use some other mechanism to ensure that each page type maps to the correct topic type in your topic map schema.

If you take this approach to defining the default topic type value, you will find that the TMCore EPiServer Module Configuration Checker will report errors when verifying the page types. These will be  messages such as:
FAIL - Page type MyPage contains an invalid topic type SI:
These messages are generated because the default value is set in code and is not stored on the Page Type record itself and so is not available to the Configuration Checker.