This is a migrated thread and some comments may be shown as answers.

Access Parent Object from Child Object

1 Answer 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Justin Woolich
Top achievements
Rank 1
Justin Woolich asked on 15 Dec 2009, 11:07 AM
Hi,

Is there any way to access the parent object from within a child object.

So for example i have a class ParentClass with a member variable IList<ChildClass> both of which are Persitent classes.

Is there an easy way to get a reference to the ParentClass from the ChildClass. So for example if i call a method on the child class and i want to access some of the properties on the Parent Class, what is the best way to do this?

Cheers

1 Answer, 1 is accepted

Sort by
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 15 Dec 2009, 12:12 PM
Hello Justin,

If you have a close relationship between the classes, like en Order-OrderLine, you can have the OrderLine reference back to the Order by using a field, say order of type Order.

public class Order
{
  private IList<OrderLine> orderLines;

  // Public properties goes here
}

public class OrderLine
{
  private Order order;

  // Public properties goes here
}

When you do a forward mapping (classes to tables) of the Order class, the wizard will ask you what the reverse field of the OrderLines list will be... here you choose the order field.... If you didn't define the order field, the only option would be {Auto}, meaning...anonymous from an OO perspective.

Hope this helps.

Regards

Henrik

Tags
General Discussions
Asked by
Justin Woolich
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Share this question
or