ForceUpdate

ForceUpdate

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


DanEssin posted on Tuesday, July 18, 2006

The code in BusinessBase says:
   public T Save(bool forceUpdate)
    {
      if (forceUpdate && IsNew)
      {

I don't think that this is correct because you could never force update of an existing record.

It should probably be:
   public T Save(bool forceUpdate)
    {
      if (forceUpdate || IsNew)
      {
 
 

RockfordLhotka replied on Tuesday, July 18, 2006

forceUpdate exists for exactly one scenario: where you are implementing a stateless web forms or web service application and need to do an update operation.

Consider a data bound Web Forms app where you want to be stateless. When the UpdateObject event is raised from CslaDataSource you need to take the data from the web form and update the data in the database. Yet you don't want to waste the time to load the object from the database just to update its data - all the data in the object is in the form (that's a prerequisite here).

So what you do is create a new instance of the object (typically calling a specialized factory for this method that simply calls the constructor directly - no data portal). Then you load the empty object with data from the form.

Then you want to call Save(), but that would do an insert because IsNew is true. What forceUpdate allows you to do is force IsNew to false, thus forcing an update operation on a "new" object.

DanEssin replied on Tuesday, July 18, 2006

I see your point. Since this related to the other message, I guess that
if the IsDirty can be assured of getting set, then I would never have to
consider using ForceUpdate in this context.

Thanks,
de

RockfordLhotka wrote:
>
> forceUpdate exists for exactly one scenario: where you are
> implementing a stateless web forms or web service application and need
> to do an update operation.
>
> Consider a data bound Web Forms app where you want to be stateless.
> When the UpdateObject event is raised from CslaDataSource you need to
> take the data from the web form and update the data in the database.
> Yet you don't want to waste the time to load the object from the
> database just to update its data - all the data in the object is in
> the form (that's a prerequisite here).
>
> So what you do is create a new instance of the object (typically
> calling a specialized factory for this method that simply calls the
> constructor directly - no data portal). Then you load the empty object
> with data from the form.
>
> Then you want to call Save(), but that would do an insert because
> IsNew is true. What forceUpdate allows you to do is force IsNew to
> false, thus forcing an update operation on a "new" object.
>
>
>
>

Copyright (c) Marimer LLC