Lazy Load a Typed List,

Posts   
 
    
craigmain
User
Posts: 22
Joined: 17-Apr-2005
# Posted on: 17-Apr-2005 10:56:24   

Hi,

I am trying to figure out the best way to achieve the following. A have a M:N relationship with an intermediate entity. (They are vehicles, vehicle groups and the link vgv (vehicle-group-vehicle)) I have built a typed list, and am using the adapter classes.

I wish to display all the groups, regardless of whether they have vehicles in them or not. The trick is that I MUST lazy load the vehicles, there is too much data to load them all at once. I want to build up the collection of vehicles as the user clicks to display the vehicles for a particular group.

I cannot find a way to slowly add to the collection. It seems to load them all at once.

DataAccessAdapter adapter = new DataAccessAdapter();
VehicleGroupVehicleListTypedList tl = new VehicleGroupVehicleListTypedList();
IRelationPredicateBucket bucket = (IRelationPredicateBucket) tl.GetRelationInfo();
adapter.FetchTypedList(tl.GetFieldsInfo(), tl, bucket);

Regards Craig

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 17-Apr-2005 15:49:26   

craigmain wrote:

Hi,

I am trying to figure out the best way to achieve the following. A have a M:N relationship with an intermediate entity. (They are vehicles, vehicle groups and the link vgv (vehicle-group-vehicle)) I have built a typed list, and am using the adapter classes.

I wish to display all the groups, regardless of whether they have vehicles in them or not. The trick is that I MUST lazy load the vehicles, there is too much data to load them all at once. I want to build up the collection of vehicles as the user clicks to display the vehicles for a particular group.

I cannot find a way to slowly add to the collection. It seems to load them all at once.

DataAccessAdapter adapter = new DataAccessAdapter();
VehicleGroupVehicleListTypedList tl = new VehicleGroupVehicleListTypedList();
IRelationPredicateBucket bucket = (IRelationPredicateBucket) tl.GetRelationInfo();
adapter.FetchTypedList(tl.GetFieldsInfo(), tl, bucket);

Regards Craig

I don't think what you are trying to do is possible with your current approach.

I would use two lists. The first list contains a list of vehicle groups; the second list contains vehicles.

When a user selects a group from the list, a second list gets populated, which uses the vehicle group PK that was selected in the first list as a predicate.

Now that I'm thinking about it, you probably could accomplish it using one list. simple_smile Just add the vehicle group PK that the user selects to the FK field of the vehicle table and refetch the list. The initial fetch (where you just want to display groups) will have to use a predicate that will not match ANY vehicles.

I hope that made sense. I just woke up. simple_smile

craigmain
User
Posts: 22
Joined: 17-Apr-2005
# Posted on: 18-Apr-2005 09:12:51   

Hi,

That kind of makes sense. What you are saying is that I add a predicate each time the user selects a particular group, and then fetch that section.

The problem now is that what happens when I need to filter the list on the client. I would then need to make a new list, and add the matching items to it.

How do I go about synchronising the two lists back again? Would it be a manual process?

Regards Craig

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Apr-2005 10:36:46   

I don't see what the problem is. You have a vehicle group and you want all vehicles in that group, but that's too much data? You could opt for paging, it's build in. Just fetch one page at the time.

Frans Bouma | Lead developer LLBLGen Pro
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 18-Apr-2005 15:38:35   

Otis wrote:

I don't see what the problem is. You have a vehicle group and you want all vehicles in that group, but that's too much data? You could opt for paging, it's build in. Just fetch one page at the time.

I think he wants all vehicle groups and all (and only) the vehicles in the group that is selected.

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 18-Apr-2005 15:47:41   

craigmain wrote:

Hi,

That kind of makes sense. What you are saying is that I add a predicate each time the user selects a particular group, and then fetch that section.

The problem now is that what happens when I need to filter the list on the client. I would then need to make a new list, and add the matching items to it.

How do I go about synchronising the two lists back again? Would it be a manual process?

If your only option is to filter on the client (I assume this question relates to your other thread), you will probably have to pull the complete list and keep a copy of it in state/session as a "master" list, then have a separate "display" list that you filter on the client and show to the user.

When the user selects a different vehicle group, you dump the display list and filter the master list to create a new display list.

This sounds like it would be an expensive way of doing it, though, especially since you've said the full list would be quite large. This has potential to bloat memory on the web server or cause the page source to be huge, depending on how you store the master list.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Apr-2005 17:44:42   

I've answered in the new thread simple_smile

Frans Bouma | Lead developer LLBLGen Pro