Lazyload used to be very easy back in CSLA 30, you just need to do null value check then decide to load or not.
With the new ‘Property’ feature introduced in CSLA 35, this becomes a little bit hard. In theory, you should check ‘Field exist’ instead of ‘null value’ by calling:
But what I found is, sometimes this is not reliable, you can easily mess FieldExist, what I’ve done was calling a GetProperty in your BO somewhere to test Lazyload. Something happen inside the GetProperty must create this field for me.
I realized that I should call ‘ReadProperty’ inside my BO not only to avoid security check, but also to avoid this messy.
In one word, the safest way to check load in getter should be: (from Rocky’s example)
if (!FieldManager.FieldExists(ChildProperty) || ReadProperty<AChild>(ChildProperty) == null)
The template from codesmith was calling SetProperty instead, I think it’s wrong because that mess up the dirty flag again.