Simple object - advice

Simple object - advice

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


RollnThndr posted on Monday, October 16, 2006

Hi,

I've been looking through the threads for some time now, bought the book and read through it so now I'd like to take a crack at a simple test app.

My use case suggests that I need a list of 'items' (datarows in a grid) and  for each item a single child collection to make up some graphical charting.  An item may have 1 to many children in it's single collection.  For this part of the app, everything would be read-only.  To edit, I will be creating other forms, which as CSLA suggests, this would be new objects, correct?

Looking for advice on the following object type to get me started.  This main data grid is obviously a collection of 'items' and then I need the child collecion and each child.  And yes, this will all be presented at the same time.  I guess think of a scheduling application.

Would I use...

ReadOnlyRootList
    ReadOnlyRoot
       ReadOnlyChildList
          ReadOnlyChild


or would I use...

ReadOnlyRootList
    ReadOnlyChild
       ReadOnlyChildList
          ReadOnlyChild

The difference of the two is the second layer.  Woiuld I use ReadOnlyChild because it would be a child of ReadOnlyRootList or would I just use ReadOnlyRoot because it would be the top object even though it is in a collection?

Thanks for an insight...  This stuff looks cool!

-Rolln

swegele replied on Monday, October 16, 2006

Hi RollnThndr,

I've been at CSLA for about 2 years now...you picked (imo) the most complicated area to ask a question - how to build your object hierarchies.  If you go over 2 levels (all being edited on the same screen) things start getting tricky.

Specifically your 2 examples deal with readonly collections and objects.  The only time I really care about Root or not is on editable objects.  I mean at the end of the day 'Root Object' only means that Save can be called publically.

Hope this helps

Sean

RollnThndr replied on Monday, October 16, 2006

Ok I see what you mean and I'm already second guessing my initial layout...  :)

Actually after a little further investigation, maybe my main item and item list should be editable.  Use case would be something like this

-User double clicks on row in grid to open that item and its children for editing.
-Saves changes (writes out to DB) and closes edit form.
These changes need to be seen on the main form.  If I was to leave the main item list readonly, could I just grab the changed item from the DB and update the main list?  Does it work this way?  Or does the list have to be setup from EditableList so that just the changed Item can be reloaded?

Basically the items in the grid are not editable in place, but when I do go to edit them and refresh the main item list, I would hope that I don't have to reload the entire main list from the db, I was hoping to just grab the item that was just edited.  This also falls in line if I was to add a new item, this would be handled on another form but would like to add it and not reload the entire list.

Hope this makes sense.  It's really giving my brain a workout at the moment...  :)




Michael Hildner replied on Monday, October 16, 2006

Hi Rollin,

You'd use your second idea. ReadOnlyRoot is meant to be a root object (no parent). So I guess it's really not the top object because it's contained in a collection.

Regards,

Mike

Copyright (c) Marimer LLC