views:

48

answers:

1

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) |
+--------------+          +------------------+
+2  A: 

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.

James Gregory
I was afraid this was going to be the case. The `Parent` class i'm trying to map to is a DTO and I was hoping the fluent mapping could handle the flattening, to avoid having to create a `Child` class.
JChristian