ChildDataPortal.Update (CSLA 3.5)

ChildDataPortal.Update (CSLA 3.5)

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


gkurtz posted on Thursday, February 28, 2008

Hello,

Seems like I'm missing something.
In my BusinessBase I implement the following inside de DataPortal_Insert() method;

Csla.DataPortal.UpdateChild( ReadProperty<UserRoles>( RolesProperty ), this );

Where UserRoles is a BusinessListBase. But in de ChildDataPortal the following is happening;

public void Update(object obj, params object[] parameters)
{
   var busObj = obj as Core.BusinessBase;
   
if (busObj != null && busObj.IsDirty == false)
  {
      
// if the object isn't dirty, then just exit
      
return;
   }

Wich renders my BusinessListBase UserRoles null because it's not a BusinessBase.
What am I doing wrong?

Thanx in advance,

Rob

RockfordLhotka replied on Thursday, February 28, 2008

That check prevents an unchanged BusinessBase from being processed. If your object is a BusinessListBase it will fall right through this check because busObj will be null. That code is correct, and isn't your problem (I don't think).

 

A root BusinessBase will implement DataPortal_XYZ methods as normal, though it will call DataPortal.UpdateChild() to update each of its child objects, which you are doing.

A child BusinessBase will implement Child_XYZ methods. If there are grandchildren, it will call DataPortal.UpdateChild() on each grandchild object.

A root BusinessListBase will implement DataPortal_XYZ methods. Its DataPortal_Update() will typically call base.Child_Update():

[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Update()
{
  using (var mgr = ConnectionManager<SqlConnection>.GetManager("dbname"))
    base.Child_Update();
}

Notice that the only reason for this code is to control the transaction and to set up the database connection or data context. Otherwise CSLA does all the work.

A child BusinessListBase needs no code, because Child_Update() is called automatically, and does the right thing.

gkurtz replied on Friday, February 29, 2008

Thanx Rocky.

Regards,
Rob

Copyright (c) Marimer LLC