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.
精彩评论