Child to Parent communication

Child to Parent communication

Old forum URL: forums.lhotka.net/forums/t/5236.aspx


Cosmin posted on Wednesday, August 13, 2008

Hi,

I need to communicate from the child to the parent. I got a list of company branches and among the branches there is a special one "All Branches" that I manually build at fetch time.
When I change some specific properties on this special branch I want to go through all the real branches and overwrite the same properties with the specific values.

Any way to do that safely? I was thinking of using events but I'm not sure if they work. I'm thinking of when saving the collection and the collection is hooked to items events. If the dataportal is remote, when the collection comes back is it still hooked to items events?
Not a remoting geek, but I feel like there will be a problem if using events

Thanks,
Cosmin

sergeyb replied on Wednesday, August 13, 2008

In the past I always preferred explicit communication between objects in a graph to anonymous.  In other words, I tend not to rely on events in such cases, but instead rely on Parent/Child properties to connect to an object to talk to.  This always seemed safer and cleaner to me than relying on events.

So, in your case in SomeProperty setter of AllBranches, you would have code like:

 

Foreach(OneBranch branch in this.Parent.Branches)

{

branch.SomeProperty = value;

}

This has been my personal preference, although I know that a lot of developers do use events for this.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: Cosmin [mailto:cslanet@lhotka.net]
Sent: Wednesday, August 13, 2008 8:57 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Child to Parent communication

 

Hi,

I need to communicate from the child to the parent. I got a list of company branches and among the branches there is a special one "All Branches" that I manually build at fetch time.
When I change some specific properties on this special branch I want to go through all the real branches and overwrite the same properties with the specific values.

Any way to do that safely? I was thinking of using events but I'm not sure if they work. I'm thinking of when saving the collection and the collection is hooked to items events. If the dataportal is remote, when the collection comes back is it still hooked to items events?
Not a remoting geek, but I feel like there will be a problem if using events

Thanks,
Cosmin


Cosmin replied on Friday, August 15, 2008

Yeah that is a straight forward solution but I'm using version 3.0 and I dont have any Parent Property on business objects. I can create one but I feel there is a problem with saving when the dataportal is remote.
If you have
BO
      Child
         {Parent} Property Pointing to BO

What happens to Parent when you do BO.Save. Save returns a new instance of BO. Is the Parent property still pointing to BO? This is what I'm worried about.
How does Clone work ?
when I save I do
     temp = BO.Clone()
     BO = temp.Save()

Cosmin.

Copyright (c) Marimer LLC