Patrick posted on Wednesday, May 14, 2008
Hi,
I would appreciate some help regaring child properties in CSLA 3.5.
This is the way Rocky recommends to declare child properties in the ProjectTracker example:
private static PropertyInfo<ProjectResources> ResourcesProperty = RegisterProperty<ProjectResources>(typeof(Project), new PropertyInfo<ProjectResources>("Resources"));
public ProjectResources Resources
{
get
{
if (!(FieldManager.FieldExists(ResourcesProperty)))
{
SetProperty<ProjectResources>(ResourcesProperty, ProjectResources.NewProjectResources());
---- or for lazy loading ----
SetProperty<ProjectResources>(ResourcesProperty, ProjectResources.GetProjectResources(this.ProjectId));
}
return GetProperty<ProjectResources>(ResourcesProperty);
}
}
So my questions are:
1) If I used lazy loading it would mean Resources isn't set during the fetch operation. So on first access to the Resources property the resources will be retrieved. Using SetProperty<ProjectResources> marks the Project business object as dirty though... but it seems like Project shouldn't really be dirty considering it just fetch some extra from the database?
2) If I did't use lazy loading and didn't set Resources during the fetch the same thing would happen. Project.IsDirty == true after accessing Resources for the first time.
3) 2) seems to mean I have to set Resources during the fetch but then Resources are an empty list (NewProjectResources()). Then it seems like that later on it will be difficult to know if Resources is an empty list because there are no records in the database or because Resources was set to NewProjectResources() during fetch?
Thanks for you help,
![Smile [:)]](/emoticons/emotion-1.gif)
Patrick
RockfordLhotka replied on Friday, May 16, 2008
Patrick:
1) If I used lazy loading it would mean Resources isn't set during the fetch operation. So on first access to the Resources property the resources will be retrieved. Using SetProperty<ProjectResources> marks the Project business object as dirty though... but it seems like Project shouldn't really be dirty considering it just fetch some extra from the database?
You can use LoadProperty() instead, thus not marking the object as dirty.
Patrick replied on Wednesday, May 21, 2008
RockfordLhotka:You can use LoadProperty() instead, thus not marking the object as dirty.
Thank you. I mainly wanted to understand though why you decided to use SetProperty in your sample before I implement it differently
![Smile [:)]](/emoticons/emotion-1.gif)
Thanks a lot,
Patrick