This is a migrated thread and some comments may be shown as answers.

Nested objects fluent mapping

1 Answer 77 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Juremir
Top achievements
Rank 2
Juremir asked on 14 Mar 2014, 02:24 PM
Hello,

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

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Boris Georgiev
Telerik team
answered on 19 Mar 2014, 12:24 PM
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.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Data Access Free Edition
Asked by
Juremir
Top achievements
Rank 2
Answers by
Boris Georgiev
Telerik team
Share this question
or