BusinessListBase.Save() implementation

BusinessListBase.Save() implementation

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


Andreas posted on Sunday, November 09, 2008

If a BusinessListBase collection instance holds many child business objects and one of its children was marked dirty due to user input changes (i. e. while editing a child instance property in a DataGridView), CSLA.NET BusinessListBase.IsDirty returns true because it returns true when only one of its children is marked as dirty. Next when BusinessListBase.Save() is called CSLA.NET Dataportal clones the whole collection incl. all its child objects on the client and then serializes them to the server where (after deserializing the collection incl. all its children) Dataportal_Update will be called.
I think that this seems to generate a lot of overhead when only one database column needs to be updated? Why does BusinessListBase.Save() not check BusinessListBase.IsSelfDirty first and if it returns false iterate through the collection and calls Save only on the child objects which are marked dirty?

JonStonecash replied on Sunday, November 09, 2008

The simplest answer is that the logic on the server may do more than just write the data to the database.  For example, it might sum a value from each child and update the parent based upon that calculation.  CSLA.NET is very flexible and cannot know what the server-side logic might do. 

In addition, unless you have a whole bunch of data, the amount of data in a single request is much less important than the number of requests.  There is typically a fair amount of fixed overhead for each request and a fairly small incrementation cost for each addition kilobyte of data sent in the request.

Jon Stonecash

Andreas replied on Sunday, November 09, 2008

Ok, I understand. But I think as a general rule that the default implementation should always generate the smallest amount of overhead as possible. If you want more than the user should override Save() in a derived classes. I think that in more than 95% of the of use cases of CSLA.NET users simply use BusinessBaseList collection to manage or aggregate child business objects, without spending additional properties. A much cleaner and more obvious design approach in other cases is to derive from BusinessBase and spend a public property of type BusinessListBase<childType> that holds the child collection.

 

vdhant replied on Sunday, November 09, 2008

Hi guys
I tend to agree that it would be good if there was a way out of the box to only send over the wire the rows that need to be updated. Whether this is the default behaviour, I don't know. But if the BusinessListBase had a property that one could set to true or false, as to whether it send all the data or only the dirty rows. This new property could be something like - OptimiseSaveDataTransfer.
Cheers
Anthony

rsbaker0 replied on Sunday, November 09, 2008

Andreas:

Ok, I understand. But I think as a general rule that the default implementation should always generate the smallest amount of overhead as possible. ...

It's "worse" than this actually. Say you have a moderately complex root object with several child lists. The root object is BusinessBase derived and the child lists derive from BusinessListBase.

If even a single field of the root is dirty and the child lists are clean, CSLA serializes the both the root and all child objects and sends it over the data portal to be saved server side.

This is the way CSLA works. I wouldn't worry about it. In practice I've found CSLA to be quite fast compared to the legacy technology it is replacing in our application.

Andreas replied on Sunday, November 09, 2008

I fully agree with the scenario you are describing because the root object is used "for more" and "not only" as a collection or container of some more relevant child business objects. My point was that when BusinessListBase.IsSelfDirty returns false, BusinessListBase seems to serve only as a collection container and then I think it is suitable when CSLA serializes only dirty marked child objects.

 

JonnyBee replied on Monday, November 10, 2008

Hi Andreas,

Please make sure to read this previous thread on the forum about the same issue you are raising:
http://forums.lhotka.net/forums/thread/25777.aspx

Rockys answer pretty much sums it all up!

/jonnybee

Copyright (c) Marimer LLC