Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top