Data Access has been discontinued. Please refer to this page for more information.

How to: Map Your Model Using Default Mapping

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

As it was described in the How to: Create a Fluent Mapping Library, the FluentMetadataSource class will hold the entire configuration for your classes and the PrepareMapping method will be your entry point for working with the Telerik Data Access FluentMapping API. Also, it is important to remember that the FluentMetadataSource class and your entities must be located in the same project.

You may note that the MapType method of the MappingConfiguration<T> class has two overloads. The first one, which is used in the last example, accepts a lambda expression that allows you to specify the property to column mapping explicitly. The second overload, specifies that all of the property mappings will be handled by Telerik Data Access, i.e. default mapping will be used.

The following code-snippets demonstrate how would look like your PrepareMapping method if you use the default mapping functionality.

using System.Collections.Generic;
using Telerik.OpenAccess.Metadata.Fluent;
namespace Data
{
   public class EntitiesModelMetadataSource : FluentMetadataSource
   {
       protected override IList<MappingConfiguration> PrepareMapping()
       {
           List<MappingConfiguration> configurations = new List<MappingConfiguration>();

           MappingConfiguration<Product> productConfiguration = new MappingConfiguration<Product>();
           productConfiguration.MapType().ToTable( "Products" );
           productConfiguration.HasProperty( p => p.Id ).IsIdentity();
           configurations.Add( productConfiguration );

           MappingConfiguration<Category> categoryConfiguration = new MappingConfiguration<Category>();
           categoryConfiguration.MapType().ToTable( "Categories" );
           categoryConfiguration.HasProperty( p => p.Id ).IsIdentity();
           configurations.Add( categoryConfiguration );

           return configurations;
       }
   }
}
Public Class EntitiesModelMetadataSource
    Inherits FluentMetadataSource
    Protected Overrides Function PrepareMapping() As IList(Of MappingConfiguration)
        Dim configurations As New List(Of MappingConfiguration)()

        Dim productConfiguration As New MappingConfiguration(Of Product)()
        productConfiguration.MapType().ToTable("Products")
        productConfiguration.HasProperty(Function(p) p.Id).IsIdentity()
        productConfiguration.FieldNamingRules.AddPrefix = "_"
        configurations.Add(productConfiguration)

        Dim categoryConfiguration As New MappingConfiguration(Of Category)()
        categoryConfiguration.MapType().ToTable("Categories")
        categoryConfiguration.HasProperty(Function(p) p.Id).IsIdentity()
        categoryConfiguration.FieldNamingRules.AddPrefix = "_"
        configurations.Add(categoryConfiguration)

        Return configurations
    End Function
End Class

Further References