# 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:

```C#
using System.Collections.Generic;
using Telerik.OpenAccess.Metadata.Fluent;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Model;

namespace SitefinityWebApp
{
   public class CustomMapping : OpenAccessFluentMappingBase
   {
       public CustomMapping(IDatabaseMappingContext context)
           : base(context)
       {
       }
       public override IList<MappingConfiguration> GetMapping()
       {
           var mappings = new List<MappingConfiguration>();
           this.MapCustomType(mappings);
           return mappings;
       }

       private void MapCustomType(IList<MappingConfiguration> mappings)
       {
           var customTypeMapping = new MappingConfiguration<CustomType>();
           customTypeMapping.MapType(x => new { }).SetTableName("sf_custom_type", this.Context);
           customTypeMapping.HasProperty(x => x.Id).HasFieldName("id").IsIdentity().IsNotNullable();
           customTypeMapping.HasProperty(x => x.LastModified).ToColumn("last_modified").IsCalculatedOn(Telerik.OpenAccess.Metadata.DateTimeAutosetMode.InsertAndUpdate).IsNullable();
           customTypeMapping.HasProperty(x => x.ApplicationName).HasFieldName("appName").ToColumn("app_name").HasLength(50).IsNullable();
           customTypeMapping.HasProperty(x => x.Title).IsNullable();
           mappings.Add(customTypeMapping);
       }
   }
}
```

## 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 `CustomTypes`project 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.

```C#
using System.Collections.Generic;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Modules.Pages.Data;

namespace SitefinityWebApp
{
   public class CustomMetadataSource : PagesMetadataSource
   {
       public CustomMetadataSource()
           : this(null)
       {
       }

       public CustomMetadataSource(IDatabaseMappingContext context)
           : base(context)
       {
       }
       protected override IList<IOpenAccessFluentMapping> BuildCustomMappings()
       {
           var mappings = base.BuildCustomMappings();
           mappings.Add(new CustomMapping(this.Context));
           return mappings;
       }
   }
}
```
