Updating Children with Editable Root Collection

Updating Children with Editable Root Collection

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


Frazer posted on Wednesday, May 06, 2009

I am struggling, trying to understand how to save changes to child objects in an editable root collection.  It appears that I have to override DataPortal_Update in the ERC class - but I am not sure what this method needs to do. Can someone post an example of a DataPortal_Update method for an ERC or otherwise provide some hints.  I am using Entity Framework - but any representative example would be useful.   Really stuck on this.

thanks,

Frazer

 

 

RockfordLhotka replied on Wednesday, May 06, 2009

Your collection is a subclass of ERLB?

In that case the objects contained in the collection must be editable root objects, and that means they need to implement all the normal DataPortal_XYZ methods - just like any normal editable root object.

The only difference from normal, is that the objects contained in the collection need different fetch code. This is because they will be fetched by the collection, not individually. This is discussed in Chapters 4-5 of the 2008 book.

Frazer replied on Wednesday, May 06, 2009

It is a subclass of ERLB *now*  :)

My confusion stems from the template on page 188 of The Book:

public class EditableRootList : 
 
BusinessListBase<EditableRootList, EditableChild>

Am I missing some errata from somewhere?

 

Frazer

RockfordLhotka replied on Wednesday, May 06, 2009

There are two types of editable collection in CSLA.

 

The first is an editable collection of editable child objects. In this case the collection is a subclass of BLB, and all children are saved as a batch when the root is saved. These child objects are normal editable child objects – nothing special.

 

The second is a dynamic collection of editable root objects. In this case the collection is a subclass of ERLB, and the root objects in the collection are saved individually as the user leaves the row of the datagrid (or deletes a row in the datagrid). The “child” objects in this case are root objects, with the exception that their fetch code is more similar to a child fetch than a root fetch (but not quite the same as normal child fetch either). But the insert/update/delete code is normal root object code – nothing special.

 

Page 188 describes the first option – a collection of child objects – not a dynamic collection of dynamic root objects, which starts on page 201.

 

Rocky

 

Frazer replied on Wednesday, May 06, 2009

Thanks Rocky -

I missed that entirely and this clears up a great deal of my confusion.  I appreciate the help.

Frazer

 

Copyright (c) Marimer LLC