BusinessListBase parent reference

BusinessListBase parent reference

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


wch posted on Tuesday, April 22, 2008

Hi, I'm new to CSLA. I have read Rocky's Expert C# 2005 Business Objects and have recently started using CSLA 3.5. I'm trying to use the Parent property in my ScheduleList BusinessListBase with the following BO hierarchy ...

Schedule - BB

--ScheduleList - BLB

-----ScheduleDay - BB

 

I would like to use a property contained in Schedule for some ScheduleDay validation logic and thought that if I exposed the ScheduleList Parent property to ScheduleDay this might work. When I examine ScheduleList's Parent property when ScheduleDay's validation method executes, it is null. I tried manually setting ScheduleList's Parent property right after loading the list  and overriding OnDeserialized  but  OnDeserialized is called after ScheduleDays validation logic executes so this won't work. Is there an event in Schedule that I could use to set ScheduleList's Parent before ScheduleDay's validation fires? Is this a wrong approach to reference root BO properties in a child BO?

Thanks much.

RockfordLhotka replied on Wednesday, April 23, 2008

In CSLA 3.5, assuming you are using the new technique for declaring child properties, the Parent property should be set automatically.

But if you are using the 3.0 technique for declaring child properties, where you declare your own private field, then Parent would be null, because in 3.0 you had to manage all those details yourself.

To use the 3.5 features for child objects, your child property should be something like:

private static PropertyInfo<ChildType> ChildProperty =
  RegisterProperty<ChildType>(typeof(ParentType),
                                                 new PropertyInfo<ChildType>("Child"));
public ChildType Child
{
  get { return GetProperty<ChildType>(ChildProperty); }
}

This allows CSLA to manage the child reference, including setting the Parent property value.

wch replied on Wednesday, April 23, 2008

Thanks for the tip! I still had properties using the old declaration method.  Your model is a great way to explore new features in .NET 3.5 ... thanks for what you do Smile [:)]

Copyright (c) Marimer LLC