Nested objects fluent mapping

Thread is closed for posting
2 posts, 1 answers
  1. Juremir
    Juremir avatar
    5 posts
    Member since:
    Jan 2012

    Posted 14 Mar 2014 Link to this post


    How i can map with Data Access Fluent Mapping the following object:

    //this class have a table
    public class Person : IEntity
       public int Id {get; set;}
       public Document Document {get; set;}
    //this class haven't a table
    public class Document
       public string Document {get; set;}

    The table Person have:

    Id - decimal
    document - varchar

  2. Answer
    Boris Georgiev
    Boris Georgiev avatar
    190 posts

    Posted 19 Mar 2014 Link to this post

    Hello Juremir,

    With Telerik Data Access you can map one or more tables to one class, but you cannot map one table to more than one class. So to achieve this behavior, you should have a transient internal property in the Person class which will be mapped to the column in the table. Then the object from the second class - Document must be created when the Person object is created and then set the Document.Document property to be linked with the transient property.

    For your convenience I have prepared and attached a sample application to demonstrate this mapping. 

    In the sample application, to set the transient property accessibility level to internal, I am creatin a static mapping located in the class file, not in the FluentModelMetadataSource. DataAccess uses DataAccess Enhancer to read and process compiled .NET assemblies for adding persistent capability. When the Enhancer processes the compiled assemblies, it searches in the code for methods of type public static MappingConfiguration<> and enhances the classes which are mapped in these methods. This is an alternative version how you can create the mapping for every class in the class itself. You should have in mind that you can have only one mapping for a class, you cannot have a static mapping in the class and another mapping in the FluentModelMetadataSource.

    I hope that helps.

    Boris Georgiev
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
Back to Top