Creating the fluent mappings
To create the specific metadata source, perform the following procedure:
-
From the context menu of folder Data, click Add » Class...
-
In the Name input field, enter TestimonialsFluentMetaDataSource.
-
Open the file TestimonialsFluentMetaDataSource.cs and add the following namespaces:
using System.Collections.Generic;
using Telerik.OpenAccess.Metadata.Fluent;
-
Change the class definition to:
public class TestimonialsFluentMetaDataSource : FluentMetadataSource
{
}
-
Create the MapTestimonialsTable method by pasting the following code:
private MappingConfiguration<Testimonial> MapTestimonialsTable()
{
// map to table
var tableMapping = new MappingConfiguration<Testimonial>();
tableMapping.MapType().ToTable("sf_testimonials");
// map properties
tableMapping.HasProperty(t => t.Id).IsIdentity(Telerik.OpenAccess.Metadata.KeyGenerator.Guid);
tableMapping.HasProperty(t => t.Name).HasLength(255).IsNotNullable();
tableMapping.HasProperty(t => t.Summary).HasLength(255).IsNotNullable();
tableMapping.HasProperty(t => t.Text).HasColumnType("varchar(max)");
tableMapping.HasProperty(t => t.Rating).IsNotNullable();
tableMapping.HasProperty(t => t.DatePosted).IsNotNullable();
tableMapping.HasProperty(t => t.Published).IsNotNullable();
tableMapping.HasProperty(t => t.UrlName).IsNotNullable();
return tableMapping;
}
-
Override the FluentMetadataSource methods by pasting the following code:
protected override IList<MappingConfiguration> PrepareMapping()
{
var mappings = new List<MappingConfiguration>();
var testimonialMapping = MapTestimonialsTable();
mappings.Add(testimonialMapping);
return mappings;
}
You inherit from FluentMetadataSource and reuse the functionality there. You override the PrepareMapping method.MapTestimonialsTable method maps the testimonial class to a database table.