loading child objects

loading child objects

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


RickR posted on Friday, January 04, 2008

I'm currently using a BO that is similar to CSLA and am considering moving to CSLA.

I wonder if someone knows the following:

I have a typical bosetup with a setup like this:

   Orders - various properties (Idnum, Order_Date, etc) plus a property for OrderItems

In a Windows form I use two binding lists to display the orders and orderitems in DataGridViews. The OrderItems binding list is bound to the OrderItems property of the Orders object.

When I load the Orders for a customer, ALL of the OrderItems child objects are loaded for Orders that are displayed in the dgv. i.e. when there are four Orders in the dgv, I get all four OrderItems objects loaded and I really only want the current Orders - OrderItems object loaded. If I page down in the dgv, a whole new set of OrderItems are loaded. If I disconnect the dgv and use textbox displays for the Orders list, I get only one child OrderItems loaded at a time.

This is not a problem when the OrderItems lists are small, but this client can sometimes have 1,0000 items in an order so it gets noticeably slow if the grid shows 20 rows.

I'm pretty sure this is a "feature" of Windows and DataGridViews but does CLSA also load all Child objects when the parent object is visible in a dgv?

 

regards,

rick

ajj3085 replied on Friday, January 04, 2008

You can have Csla do whatever you want.  What I would probably do is create two ReadOnlyListBase subclasses, OrderList and OrderItemList.  OrderList contains the orders you want to see (filtered by customer, or not, up to you).  Then as the selection changes on the Orders grid, load an OrderItemsList for just that particular order (on a background thread, so your UI doesn't lock).  Then bind that OrderItemsList to the binding source of the items grid. 

So I'd probably have something like this:

public sealed class OrderList : ReadOnlyListBase<OrderInfo> {
   public static OrderList GetOrders( // optionally add criteria here if you like ) {
   }
}

public sealed class OrderItemList : ReadOnlyListBase<OrderItemInfo> {
   public static OrderItemList GetItems( OrderInfo order ) {
   }
}

The obviously have an OrderInfo and OrderItemInfo class.

HTH
Andy

RickR replied on Friday, January 04, 2008

Thanks Andy,

Yes, I have tried that type of setup and it does work, however it does not seem to take advantage of the automatic loading and other features of a Child object (unless I am missing something).

I would like to load and display the OrderItemsList automatically since it is a child of the OrdersList objects, but when I use the datagridview, all the child OrderItems load. I want the child OrdersItemList to load only when needed, i.e. when the client switches to a tab with a datagridview or textboxes that are bound to the child.

In this senario, does Csla do the same thing?

Regards,

Rick

ajj3085 replied on Friday, January 04, 2008

Rick,

If all the order items aer loading, that's probably has more to do with how you've coded your objects than a datagridview... unless you're using Ado.net objects perhaps. 

With Csla though, you can certainly create an Items property on the OrderInfo object, and have it do a lazy load so that it will only load once that property is gotten.  I don't think the grid will attempt to get the Items property until it is actually used, but I'm not 100% sure. 

Copyright (c) Marimer LLC