Lazy loading BusinessListBase several levels down

Lazy loading BusinessListBase several levels down

Old forum URL:

ballistic posted on Monday, November 15, 2010

This is my current object graph


 - PhotoList (BusinessListBase)

 - - Photo

 - - - Tags (BusinessListBase)

 - - - - Tag

I am currently loading the PhotoList and Tags using lazy loading. Within the Album class, to load the list of photos I use:

        public IPhotoList PhotoList
                if (!FieldManager.FieldExists(PhotoListProperty))
                    LoadProperty(PhotoListProperty, IoC.Resolve<IPhotoList>().FindByAlbumIdMemberId(this.Id, this.MemberId));
                return GetProperty(PhotoListProperty);
            set { SetProperty(PhotoListProperty, value); }

This works fine.

However, when I use the same code in the Photo class to load the Tags, the FieldManager.FieldExists always returns true.

From the looks of it, when the PhotoList gets loaded, it also adds Tags property to the FieldManager.  Is there a way to prevent that or to have a different check in the property so I can continue using lazy-loading?


ballistic replied on Tuesday, November 16, 2010

Also, probably related to this problem within the Photo's DeleteSelf method I call FieldManager's UpdateChildren so that it would delete the tags first and then delete the photo.

protected void Child_DeleteSelf(Album parent)

However, the Tag's Child_DeleteSelf is never called, so I get

The DELETE statement conflicted with the REFERENCE constraint

This is the first time I work with such a deep object graph so not really sure how stuff should be done.


Thank you,

 - Andy

ballistic replied on Tuesday, November 16, 2010

So did a little more research and it seems this is a know issue, but it's not a bug w/ CSLA.
"When you manually call the DataPortal method, you are accessing the field in your code – which triggers the creation of the field. So you do need to wrap that code with an exists check to avoid the issue. There’s really nothing CSLA can do for you in that case."

Also, in

"Clearly some code is causing the creation of the FieldData object. Which means there's an unprotected call to one of the read/get/load/set property methods against that field - probably in your insert/update data code.

By unprotected I mean that it needs to be wrapped by a check for FieldExists."


In their case, it was an update, but in my case I'm doing a Fetch. Can someone please show me how I should protect the property so that the DataPortal does not set the field and thereby add it to FieldManager?

Also, if it makes a difference, I am using CSLA 3.8.

Thank you
- Andy

ballistic replied on Tuesday, November 16, 2010

I was finally able to solve the problem by adding the RelationshipType to the RegisterProperty

RelationshipTypes.Child | RelationshipTypes.LazyLoad

Copyright (c) Marimer LLC