Lazy Loading Fields

Posts   
 
    
jader201
User
Posts: 33
Joined: 20-Mar-2007
# Posted on: 24-Apr-2007 17:53:12   

I'm still new to LLBLGen Pro and the whole concept of O/RM, so bare with me. simple_smile

I am trying to figure out the best method for lazy-loading fields from a table into an entity. For example, I have a large table with many columns, and I have a screen to maintain the data in this table. I have a dropdown where I select the record I want to update, which has the value set to the table's ID, and the text set to a meaningful value (i.e. "Name").

I have my datasource set to a collection of this entity, and my bindingsource set to the datasource. When I load the form, I load the datasource collection using myCollection.GetMulti(null). The way I understand it, this will load the collection with every field of every record, and this obviously takes a while.

Ideally, I want to just load the data required for the dropdown (ID and Name), and then when the selection on the bindingsource changes, lazy-load the remaining data on the table.

I've researched this, and I'm assuming this is possible, I'm just not looking in the right place. I'm aware of PrefetchPaths, but as I understand it, this is for lazy loading related tables, not individual fields on the same table. I'm also aware of Dynamic Lists, but from what I've read about these (granted, I don't have a complete understanding of their use), this doesn't seem like an elegant approach to what I'm trying to accomplish.

What is the best way to accomplish this?

Thanks in advance.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2007 10:21:50   

You can accomplish this in many ways.

Option #1: You can create a TypedList or a DynamicList (both are dataTables), with the (ID & Name) fields only, then you can bind to that dataTable, and when selecting an item (ID & Name), you can fetch an entityCollection to bind it to the rest of the controls.

If you want Lazy Loading, then you can do one of the following:

Option #2: In the Designer Define a new entity based on the same table but with the ID and Name fields only. From the Designer also, you should define a relation between this entity and the original one. This way you can fetch the small size entity and lazy load the bigger one.

Option #3: Same as option 2, but instead of defining a new entity, you may define a database view, and map this to an entity (the smaller entity). Then you should define a relation between them, and continue as before.

jader201
User
Posts: 33
Joined: 20-Mar-2007
# Posted on: 25-Apr-2007 16:07:23   

Thanks for the reply.

I think it would be much better if there were a way to specify, up front when loading the entity, the fields that you want preloaded, and then when accessing the other fields, retrieve the remaining fields. Maybe this could be considered for future updates? I could see this being very useful in many situations, and would remove the need of having to create custom entities just for the sake of loading less data up front. I believe I've seen this feature in other tools as well. I think of using custom entities in situations where you need to merge two or more tables, not for building field subsets of single tables.

The reason I'm not crazy about your suggested approaches, is that I could see us having to do this for every table in our database (or at least most of them), which removes much of the convenience of the automation of LLBLGen. If we have a screen for maintaining each table, and want to give the users a simple list of items (records) to choose from and edit, then we'll either have to create separate entities for each table, or will have to go ahead and load everything up front, neither of which are ideal.

Thanks again.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Apr-2007 17:52:35   

That's a feature we are studying, might be added to the next version. ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8959

jader201
User
Posts: 33
Joined: 20-Mar-2007
# Posted on: 25-Apr-2007 17:58:57   

Thanks, that's good to hear.