Extend Sitefinity CMS data model: Create the fluent mappings

After you create the custom type class, you implement the fluent mappings that map your model classes to the database tables. To implement the fluent mappings for your data provider, you must create the following classes:

  • CustomMapping
  • CustomMetadataSource

To use the mappings in the data provider, you must return an instance of the CustomMetaDataSource class in the GetMetaDataSource method of the provider.

Create the CustomMapping class

The CustomMapping class defines the mapping for the CustomType model class. To create the class:

  1. In Visual Studio, open the context menu of the CustomTypes project and click Add » Class.
  2. Name the class file CustomMappings.cs and click Add.
  3. Make the CustomMappings class inherit the OpenAccessFluentMappingBase class.
  4. Create class constructor constructor.
  5. Implement the OpenAccessFluentMappingBase abstract class.
    To implement the class, you must override the GetMapping abstract method. In the method, you create the mappings. You map the CustomType class to the sf_custom_type table and set the properties for each member.

Use the following code sample:

Create the CustomMetaDataSource class

The CustomMetadataSource class wraps the mappings and exposes them to the OpenAccess data provider. To create the class:

  1. In Visual Studio, open the context menu of the CustomTypesproject and click Add » Class.
  2. Name the class file CustomMetadataSource.cs and click Add.
  3. Make the CustomMetadataSource class inherit the PagesMetadataSource class.
    The PagesMetadataSource class is inherits from the ContentBaseMetadataSource class, which provides the basic mappings for the content, security, and workflow that need to be present in content based modules. 
  4. Create the class constructors.
  5. Override the BuildCustomMappings method. In the method, create an instance of the CustomMapping class and add the instance to the default set of mappings.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?