开发者

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

开发者 https://www.devze.com 2022-12-29 07:24 出处:网络
I want to map the Name column from the Child table into the Parent object. How do 开发者_如何学JAVAyou do this (using Fluent NHibernate)?

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

精彩评论

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

关注公众号