Newbie question BusinessListBase and Child Class/Root Class

Newbie question BusinessListBase and Child Class/Root Class

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


Martin Sørensen posted on Thursday, May 22, 2008

Newbie question BusinessListBase and Child Class

 

Hey All. I’m new to CSLA and is starting on my first project. I’m trying to make at list of root objects.

 

 I’m using CSLA 3.5 and would like to see an example of at List of Editable Root objects, These objects come out of a database.

 

I have been looking at the Project Tracker example but still not sure about the right way to this.

 

Regards Martin

 

 

RockfordLhotka replied on Thursday, May 22, 2008

It sounds like your list object is the root - the object you want to fetch. And it contains other objects.

There are two models:

  1. Root list of child objects - in this model you fetch/save the list, and the objects in the list are retrieved/saved as a group - batch transaction for the insert/update/delete
  2. Dynamic list of root objects - in this model you fetch the list, but individual objects in the list are saved as the user moves from row to row in a data bound Windows Forms grid - the saves are immediate and individual

Model 1 is far more common and is what you'll find in ProjectTracker and the Expert 2005 Business Objects book.

Model 2 exists to support a specific user experience in Windows Forms (and probably WPF once it has a data grid control), and is far less common. You'll find details about this in the CSLA .NET Version 2.1 Handbook ebook, because Csla.EditableRootListBase was introduced in version 2.1.

Martin Sørensen replied on Thursday, May 22, 2008

Hi Rocky thanks for your replay and your great work…. Maybe I should try to explain that I’m trying to….

 

This is properly a design question ;o)

 

I have an object… in this case “Site” that have different methods I want to executed. I have a number of “Site” object what I want to executed a method on. So my idée was to put these object in at List and make a method on that list object that would loop thru all object and executed a method on that object and at the same time update data in that object. This would properly be a windows service that would invoke the list object

 

 

Would that be a subject for model2 ???, if this is the case is this root object in the dynamic list also a normal root object

 

Regards Martin

SomeGuy replied on Thursday, May 22, 2008

What you probably want is some kind of Controller object that loads a simple list of Sites and processes each one. That way, you only load a light list of Sites and only have one full Site at any given moment.

Class SiteProcessor
{
   public void Process()
   {
      SiteList list = SiteList.GetList();
      foreach(SiteInfo item in list)
      {
         Site obj = Site.GetSite(item.Id);
         obj.Process();
      }
   }
}

Martin Sørensen replied on Thursday, May 22, 2008

Thanks … this was also one of my first idea’s but I thought  that I could spare a class ;o)  by using a Root List… I will try your suggestion

 

Regards Martin

RockfordLhotka replied on Thursday, May 22, 2008

I agree with someguy. Also, this is probably a scenario where you'd want to use a command object - your 'controller' is a process object, and so should subclass CommandBase. The loop should be in the DataPortal_Execute() method.

Also, if you want an overall transaction, you can put the Transactional attribute on the DP_Execute() method. And if you are using TransactionScope, make sure to open your db connection outside the loop and reuse the same connection for all the objects in the loop.

Copyright (c) Marimer LLC