Data binding not lazy loading

Data binding not lazy loading

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


TheSquirrelKing posted on Thursday, March 13, 2008

Hello again everyone. I'm back with another bit of curious behaviour to share. I'm working on an imaging-related project (still unfortunately stuck at CSLA version 2.1.2) that involves a root Project object that contains a child collection of Roll objects which each, in turn, contain a child collection of Image objects. With that created, I used data binding to populate a GUI that allows a user to edit a Project's properties, and everything worked well.

That is, it seemed to work well until I created Project instances that included multiple rolls containing a couple hundred Images each. For some reason, despite the fact that all my collections are set up lazy-load style, and despite the fact that I have not bound the Project's Roll collection object to the interface, when I load one of these well-populated Project instances in the GUI, the application loads every single Roll and every Image contained therein. This results in an especially noticeable delay.

I should mention that this behaviour doesn't occur outside of the data bound GUI (ie: when I run test classes that load Project objects, or when I use GUIs created the "old-fashioned" way).

Has anyone else run into anything like this? Any advice?

Thanks!
-TSK

RockfordLhotka replied on Thursday, March 13, 2008

I'm guessing you trigger the lazy load so it occurs when the property is accessed?

Data binding is probably accessing the property immediately. In fact, if the property is bound it most certainly will access it immediately.

So odds are your lazy loading is working fine, but it is being triggered when you don't expect it. To prevent this, you need to ensure that the property in question is NOT data bound - at least not until you actually want to have the data displayed/loaded.

TheSquirrelKing replied on Friday, March 14, 2008

Well that's the thing, I've added binding sources for Project and for some of the other child object collections it contains, but the Roll collection is not bound, has no binding source, and is not even referred to anywhere in the GUI. I'm stumped.

ajj3085 replied on Friday, March 14, 2008

Your best bet then is to put a breakpoint in your code that does the lazy loading, then looking at the call stack to see what is causing the load.

I think Infragistics grid loads children even if they aren't displayed yet.

TheSquirrelKing replied on Friday, March 14, 2008

Yeah, so I'm having a "why didn't I check the call stack in the first place" moment. As it turns out, this behaviour was occurring because databinding calls IsValid() when it loads. Unlike my IsDirty() implementation, my IsValid() implementation was returning:

Return MyBase.IsValid AndAlso Rolls.IsValid ... etc.

instead of checking if the collections were equal to Nothing like this:

Return MyBase.IsValid AndAlso (_rolls IsNot Nothing AndAlso _rolls.IsValid) ... etc.

I think I had decided to leave IsValid() as-is because I was thinking that if a collection was set to nothing, then it shouldn't be valid. Or something like that. Either way, everything is working lightning-fast again, and I thought I would post this follow-up in case anyone else has the same lapse in concentration ;)

TheSquirrelKing replied on Saturday, March 15, 2008

Er, rather:

Return MyBase.IsValid AndAlso (_rolls Is Nothing OrElse _rolls.IsValid) ... etc.

 

Copyright (c) Marimer LLC