Creating the fluent mappings
Defining the specific fluent mapping
To define the specific fluent mapping, perform the following procedure:
-
From the context menu of folder Model, click Add » New Item...
-
In the left pane, select Visual C# » Code.
-
Click Class and in the Name input field, enter JobsFluentMapping.
-
Open the file JobsFluentMapping.cs and add the following namespaces:
using System.Collections.Generic;
using Telerik.OpenAccess.Metadata.Fluent;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Model;
-
Change the class definition to:
public class JobsFluentMapping : OpenAccessFluentMappingBase
{
}
-
Create the constructor in the following way:
public JobsFluentMapping(IDatabaseMappingContext context)
: base(context)
{
}
-
Override the GetMapping method by pasting the following code:
public override IList<MappingConfiguration> GetMapping()
{
var mappings = new List<MappingConfiguration>();
MapItem(mappings);
return mappings;
}
private void MapItem(IList<MappingConfiguration> mappings)
{
var itemMapping = new MappingConfiguration<JobApplication>();
itemMapping.HasProperty(p => p.Id).IsIdentity();
itemMapping.MapType(p => new { }).ToTable("sfex_jobapplications");
itemMapping.HasProperty(p => p.Phone);
itemMapping.HasProperty(p => p.FirstName);
itemMapping.HasProperty(p => p.LastName);
itemMapping.HasProperty(p => p.Text);
itemMapping.HasProperty(p => p.Referral);
mappings.Add(itemMapping);
}
All mappings inherit OpenAccessFluentMappingBase and override the GetMapping method. First, you create a mapping configuration. Then, you specify the name of the table. Finally, you specify the properties in the mapping.
Creating the specific metadata source
To create the specific metadata source, perform the following procedure:
-
From the context menu of folder Model, click Add » New Item...
-
In the left pane, select Visual C# » Code.
-
Click Class and in the Name input field, enter JobsFluentMetadataSource.
-
Open the file JobsFluentMetadataSource.cs and add the following namespaces:
using System.Collections.Generic;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Modules.GenericContent.Data;
-
Change the class definition to:
public class JobsFluentMetadataSource : ContentBaseMetadataSource
{
}
-
Create the constructors in the following way:
public JobsFluentMetadataSource()
: base (null)
{
}
public JobsFluentMetadataSource(IDatabaseMappingContext context)
: base (context)
{
}
-
Override the BuildCustomMappings method by pasting the following code:
protected override IList<IOpenAccessFluentMapping> BuildCustomMappings()
{
var sitefinityMappings = base.BuildCustomMappings();
sitefinityMappings.Add(new JobsFluentMapping(this.Context));
return sitefinityMappings;
}
You inherit from ContentBaseMetadataSource and reuse the functionality there. You must override the BuildCustomMappings method by adding JobsFluentMapping to the mappings created in the base implementation.