开发者

NHibernate many-to-one loading alternative

I have a Parent/Child object/mapping as follows:

class Parent {
  int Id;
  string name;
  List<Child> children;
}

<bag name="Children" cascade="all" lazy="false ">
  <key column="ParentId" />
  <one-to-many class="Child" />
</bag>


class Child {
  int Id;
  Parent Parent;
  string Name;
}

<many-to-one name="Parent" column="ParentId" />

I don't want to use the property 开发者_运维技巧Parent Parent in Child; I want to use int ParentId. How would I go about mapping that?


If you don't want an association, but rather only the ParentId as an int in the Child class, you don't map the association, but instead map the ParentId just as any other property.

If on the other hand you want both, you simple implement the ParentId int property in Child as an derived property (with no mapping) that delegates to Parent.Id.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜