Disable lazy loading in selfservicing possible?

Posts   
 
    
TlighT
User
Posts: 20
Joined: 19-Aug-2004
# Posted on: 28-Feb-2005 18:22:04   

This sounds really stupid, but is there any way of disableing lazy loading in self-servicing and use only prefetch paths?

Let me explain why:

I have to extend an old application which uses selfservicing. We use adapter for all projects now, and I like the adapter model so much better than selfservicing but I have too little time to convert the whole thing to adapter.

For our current projects, I've been using a service layer on which most of the BL functionality is defined. These services contain the logic to communicate with the database (using llblgen) and the other BL. The asp.net pages use only these services to fetch/store the entities they need. To be clear: the entities do not (yet) pass a physical tier, it's just a way to achieve better code separation.

Since selfservicing is also able to use prefetch paths, it should be possible to more or less use the same architecture for the old selfservicing application.

But I'm afraid that if other developers (or I myself for that matter simple_smile ) work on the project, they might not prefetch everything correctly, and if this happens, it will go unnoticed, for any related entity which is not prefetched will be loaded on demand instead.

So is there any way of forcing everything to be prefetched and/or disableing loading on demand?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 28-Feb-2005 18:40:13   

You can, but it requires some template writing. The lazy loading code uses flags to see if lazy loading was already triggered. So if you can set these to true, the lazy loading code will never work, unless the developer either explicitly calls GetMulti... (true) to force a fetch, or sets AlwaysFetch... to true, which switches off selfservicing the other way around.

Two class scenario, create a new template config file, and add a new binding: Custom_EntityBaseTemplate, to which you bind the new file switchOffLLBaseInclude.template

to this template you add:


protected void SwitchOffLazyLoading()
{
<[Foreach RelatedEntity OneToMany CrLf]><[If Not MappedFieldRelationIsHidden]>  _alreadyFetched<[MappedFieldNameRelation]>=true;<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity ManyToMany CrLf]><[If Not MappedFieldRelationIsHidden]> _alreadyFetched<[MappedFieldNameRelation]>=true;<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity ManyToOne CrLf]><[If Not MappedFieldRelationIsHidden]>  _alreadyFetched<[MappedFieldNameRelation]>=true;<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity OneToOne CrLf]><[If Not MappedFieldRelationIsHidden]>   _alreadyFetched<[MappedFieldNameRelation]>=true;<[EndIf]><[NextForeach]>
}

regenerate your code with that template set.

All your entities now have a method which can switch off lazy loading. To make this automatic, add to the constructors in the derived entity classes a call to this method. Done simple_smile

Frans Bouma | Lead developer LLBLGen Pro
TlighT
User
Posts: 20
Joined: 19-Aug-2004
# Posted on: 28-Feb-2005 22:43:43   

Thanks! I will try that.