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

How to: Use Default Mapping with Inheritance

This topic demonstrates you how to configure inheritance mapping by using default mapping of the Telerik Data Access Fluent API. When you use default mapping, the FluentMetadataSource takes care of the property to column mapping. On the other hand, when you use explicit mapping configuration you are explicitly specifying the property to column mapping. The explicit mapping configuration gives you more control over the column naming, as well as it allows you to create partially mapped models. In the Horizontal Inheritance and Flat Inheritance topics an explicit mapping configuration is used. The following code-snippets show you how to configure horizontal and flat inheritance by using default mapping.

For more information, check out the Using Default Mapping Functionality and Mapping CLR Types topics.

  • Flat inheritance with default mapping

    public class MyFluentMetadataSource : FluentMetadataSource
    {
       protected override IList<MappingConfiguration> PrepareMapping()
       {
           IList<MappingConfiguration> preparedConfigurations = new List<MappingConfiguration>();
    
           MappingConfiguration<Animal> animalConfiguration = new MappingConfiguration<Animal>();
           animalConfiguration.MapType();
           animalConfiguration.HasProperty(x => x.Name).IsIdentity();
    
           MappingConfiguration<Dog> dogConfiguration = new MappingConfiguration<Dog>();
           dogConfiguration
               .MapType()
               .Inheritance(Telerik.OpenAccess.InheritanceStrategy.Flat);
    
           MappingConfiguration<Cat> catConfiguration = new MappingConfiguration<Cat>();
           catConfiguration
               .MapType()
               .Inheritance(Telerik.OpenAccess.InheritanceStrategy.Flat);
    
           preparedConfigurations.Add(animalConfiguration);
           preparedConfigurations.Add(dogConfiguration);
           preparedConfigurations.Add(catConfiguration);
           return preparedConfigurations;
       }
    }
    
    Public Class MyFluentMetadataSource
     Inherits FluentMetadataSource
     Protected Overrides Function PrepareMapping() As IList(Of MappingConfiguration)
      Dim preparedConfigurations As IList(Of MappingConfiguration) = New List(Of MappingConfiguration)()
    
      Dim animalConfiguration As New MappingConfiguration(Of Animal)()
      animalConfiguration.MapType()
      animalConfiguration.HasProperty(Function(x) x.Name).IsIdentity()
      animalConfiguration.FieldNamingRules.AddPrefix = "_"
    
      Dim dogConfiguration As New MappingConfiguration(Of Dog)()
      dogConfiguration.MapType().Inheritance(Telerik.OpenAccess.InheritanceStrategy.Flat)
      dogConfiguration.FieldNamingRules.AddPrefix = "_"
    
      Dim catConfiguration As New MappingConfiguration(Of Cat)()
      catConfiguration.MapType().Inheritance(Telerik.OpenAccess.InheritanceStrategy.Flat)
      catConfiguration.FieldNamingRules.AddPrefix = "_"
    
      preparedConfigurations.Add(animalConfiguration)
      preparedConfigurations.Add(dogConfiguration)
      preparedConfigurations.Add(catConfiguration)
      Return preparedConfigurations
     End Function
    End Class
    
  • Horizontal inheritance with default mapping

    public class MyFluentMetadataSource : FluentMetadataSource
    {
       protected override IList<MappingConfiguration> PrepareMapping()
       {
           IList<MappingConfiguration> preparedConfigurations = new List<MappingConfiguration>();
    
           MappingConfiguration<Animal> animalConfiguration = new MappingConfiguration<Animal>();
           animalConfiguration.MapType().Inheritance(Telerik.OpenAccess.InheritanceStrategy.Horizontal);
    
           MappingConfiguration<Dog> dogConfiguration = new MappingConfiguration<Dog>();
           dogConfiguration.MapType();
           dogConfiguration.HasProperty(x => x.Name).IsIdentity();
    
           MappingConfiguration<Cat> catConfiguration = new MappingConfiguration<Cat>();
           catConfiguration.MapType();
    
           preparedConfigurations.Add(animalConfiguration);
           preparedConfigurations.Add(dogConfiguration);
           preparedConfigurations.Add(catConfiguration);
           return preparedConfigurations;
       }
    }
    
    Public Class MyFluentMetadataSource
     Inherits FluentMetadataSource
     Protected Overrides Function PrepareMapping() As IList(Of MappingConfiguration)
      Dim preparedConfigurations As IList(Of MappingConfiguration) = New List(Of MappingConfiguration)()
    
      Dim animalConfiguration As New MappingConfiguration(Of Animal)()
      animalConfiguration.MapType().Inheritance(Telerik.OpenAccess.InheritanceStrategy.Horizontal)
      animalConfiguration.FieldNamingRules.AddPrefix = "_"
    
      Dim dogConfiguration As New MappingConfiguration(Of Dog)()
      dogConfiguration.MapType()
      dogConfiguration.HasProperty(Function(x) x.Name).IsIdentity()
      dogConfiguration.FieldNamingRules.AddPrefix = "_"
    
      Dim catConfiguration As New MappingConfiguration(Of Cat)()
      catConfiguration.MapType()
      catConfiguration.FieldNamingRules.AddPrefix = "_"
    
      preparedConfigurations.Add(animalConfiguration)
      preparedConfigurations.Add(dogConfiguration)
      preparedConfigurations.Add(catConfiguration)
      Return preparedConfigurations
     End Function
    End Class