开发者

In NHibernate (Fluent), How do you map a property on referenced object into parent object?

I want to map the Name column from the Child table into the Parent object. How do 开发者_如何学JAVAyou 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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜