Creating the fluent mappings

To create the specific metadata source, perform the following procedure:

  1. From the context menu of folder Data, click Add » Class...

  2. In the Name input field, enter TestimonialsFluentMetaDataSource.

  3. Open the file TestimonialsFluentMetaDataSource.cs and add the following namespaces:

    using System.Collections.Generic;
    using Telerik.OpenAccess.Metadata.Fluent;

  4. Change the class definition to:

    public class TestimonialsFluentMetaDataSource : FluentMetadataSource
    {
     
    }

  5. 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;
    }

  6. 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.

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK