Missing support for DataPortal_Insert in the Client DataPortal and ObjectFactoryAttribute

Missing support for DataPortal_Insert in the Client DataPortal and ObjectFactoryAttribute

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


jmcd posted on Thursday, September 18, 2008

I'm working on an implementation of the ObjectFactoryAttribute pattern based on Rocky's blog post http://www.lhotka.net/weblog/CSLANETObjectFactoryAttribute.aspx

I like the control the approach gives me with respect to checking cross-cutting concerns before invoking DataPortal methods.  However, I have noticed that in the latest source (http://lhotka.net/files/csla36/cslacs-3.6.0-080906.zip) there seems to be missing support for calling a Business Object's DataPortal_Insert method.  In the ObjectFactoryAttribute class there are class properties available for describing the methods Create, Fetch, Update and Delete but no Insert.  Additionally, when you call Save on a new Business Object instance, the Client DataPortal only decides whether to call Update or Delete whereas in 3.5 it decided whether to call Insert, Update or Delete.

Is the omitted support for Insert a bug or has the design changed?

jmcd replied on Friday, September 19, 2008

I think I've answered my own question so thought I should share my findings.

I think the Update method in the Factory class is to decide what to do (like the DataPortal Update) i.e. either call Update, Delete or Insert based on the class properties of the object

My Update method looks something like:

            if(busObj.IsDeleted)
            {
                //perform a Delete Self
            }
            else if (busObj.IsNew)
            {
                // perform an Insert
            }
            else
            {
               //perform an Update
            }

RockfordLhotka replied on Friday, September 19, 2008

That is exactly right. When you use the ObjectFactory attribute, your factory assumes all responsibility for interacting with any business objects - in any way you choose. The data portal does as little as possible, allowing you the flexibility to do as much as possible.

You should look at the Csla.Server.ObjectFactory base class. While you don't have to inherit from this class, it is a good choice, because it provides methods allowing you to manipulate the state of business objects (MarkNew(), MarkOld(), MarkAsChild()).

Copyright (c) Marimer LLC