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) |
+--------------+ +------------------+
What you’re trying to do just isn’t a very good design, I’m afraid. Your
Parentshould have a relationship to theChildentity via a many-to-one (Referencesin Fluent). That way you’d have aChildproperty in yourParentclass.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.