2
votes

I want to map the Name column from the Child table into the Parent object. How do you do this (using Fluent NHibernate)?

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

Tables

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

1 Answers

3
votes

What you're trying to do just isn't a very good design, I'm afraid. Your Parent should have a relationship to the Child entity via a many-to-one (References in Fluent). That way you'd have a Child property in your Parent class.

If you're trying to produce a flattened model, I'd recommend you create a DTO and use something like Jimmy Bogard's AutoMapper to flatten the hierarchy.