Help on root objects vs root collections

Help on root objects vs root collections

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


DanEssin posted on Monday, August 14, 2006

You'd think that I'd have this figured out by now but I am having trouble deciding which set of objects to select to implement my requirement.

What I want is a form with 2 grids. Each row in the upper grid is a "master" row. When I click it, I want the "detail" rows related to that master row to appear in the lower grid. Both grids need to be editable.

I have tried using a combination of EditableRootList and Editable Child for the upper grid, but:
1 - Editable Root contains methods to add a new child but it is not set up to act as a child because it cannot accept the data reader from editable root list.
2 - The root list object does not implement a method to add an item to the list

If I could get the upper grid wirling, I could duplicate the structure for the lower grid, although, in this case it would be cleaner (since there a small number of records) if I could just read all the masters and all of the details, establish a relationship between the 2 sets and filter what showed in the lower grid based on which row was selected in the upper. This, however, does not seem to be possilbe.

At this point I'm hopelessly confused about which classes to select and how to wire them up to get what I need. If someone could shed some light on this for me it would be a big help.

tia,
Dan

SteveChadbourne replied on Monday, August 14, 2006

I do this although in a read-only fashion.

I use a ReadOnlyListBase/ReadOnlyBase for the top grid. I have a separate ReadOnlyListBase/ReadOnlyBase for the bottom grid. I don't make the bottom grid objects children of the top grid objects for performance reasons.

OnSelect on the top grid calls DataBind on the bottom grid. The CslaDataSource for the bottom grid calls OnSelectObject which looks like:

protected void BottomGridDataSource_SelectObject(object sender, Csla.Web.SelectObjectArgs e)

{

   e.BusinessObject = GetBottomList();

}

GetBottomList() calls the factory method on your bottom grid list object and passes in TopGrid.SelectedValue;

DanEssin replied on Wednesday, August 23, 2006

I guess that I'm going to be drowning in classes. I'm going to have listClass/itemClass for the upper grid and listClass/itemClass for the lower grid. Do I also need editable root classes to support adding new rows to each grid or can I use the child objects in isolation somehow to call the insert methods?

Thanks,
Dan

SteveChadbourne wrote:

I do this although in a read-only fashion.

I use a ReadOnlyListBase/ReadOnlyBase for the top grid. I have a separate ReadOnlyListBase/ReadOnlyBase for the bottom grid. I don't make the bottom grid objects children of the top grid objects for performance reasons.

OnSelect on the top grid calls DataBind on the bottom grid. The CslaDataSource for the bottom grid calls OnSelectObject which looks like:

protected void BottomGridDataSource_SelectObject(object sender, Csla.Web.SelectObjectArgs e)

{

   e.BusinessObject = GetBottomList();

}

GetBottomList() calls the factory method on your bottom grid list object and passes in TopGrid.SelectedValue;




RockfordLhotka replied on Wednesday, August 23, 2006

DanEssin:

I have tried using a combination of EditableRootList and Editable Child for the upper grid, but:
1 - Editable Root contains methods to add a new child but it is not set up to act as a child because it cannot accept the data reader from editable root list.
2 - The root list object does not implement a method to add an item to the list


I assume your issue is with a set of code-gen templates? Because if you are coding this by hand it is a non-issue. In both CSLA 1.x and 2.x you can implement code in the collection to allow the grid to add new child objects, and obviously you can implement factory methods in your child class like I show in the books to accept the data reader from a parent.

Copyright (c) Marimer LLC