In NHibernate (Fluent), How do you map a property of the object you are referring to to the parent object?

I want to map a column Name

from a table Child

to an object Parent

. How do you do this (using Fluent NHibernate)?

public class Parent
{
   public int Key { get; set; }
   public string ChildName { get; set; }
}

      

Table

+--------------+          +------------------+
| Parent       |          | Child            |
+--------------+          +------------------+
| Key      INT |     +--->| Key  INT         |
| ChildKey INT |-----+    | Name VARCHAR(20) |
+--------------+          +------------------+

      

+2


a source to share


1 answer


What you are trying to do is not a very good design, I'm afraid. Yours Parent

should relate to the object Child

through many-to-one ( References

in Fluent). This way you will have a property Child

in your class Parent

.



If you are trying to create a flattened model, I would recommend that you create a DTO and use something like Jimmy Bogard AutoMapper to flatten the hierarchy.

+3


a source







All Articles