Lazyload in CSLA 35

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:

if (!FieldManager.FieldExists(ChildProperty))

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)

LoadProperty<AChild>(ChildProperty, AChild.GetChild());

The template from codesmith was calling SetProperty instead, I think it’s wrong because that mess up the dirty flag again.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s