IsDirty Check Nessesary on child inserts?

IsDirty Check Nessesary on child inserts?

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


antoan posted on Friday, August 11, 2006

As in the case of ProjectResource.Insert(...) of the Project Tracker application:

We check to see if the the object is in a dirty state before we insert, if not the operation is ignored:

// if we're not dirty then don't update the database
if (!this.IsDirty) return;

What I'm missing is why we dont base this decision on the state of IsNew since the two always coincide - if new then dirty, ensured by the MarkNew() base method?

I cannot think of a senario when the thing is new and insertable but not dirty?

xal replied on Friday, August 11, 2006

You could be updating existing data, and in that scenario, the object would not be marked as IsNew, but if you altered it, then it would be dirty.
New objects are always assumed to be dirty, because it's not something that is already persisted, so in a sense, isdirty tracks whether the state of the object is persisted or not, whereas IsNew only tracks if you should be inserting or updating.

So, If the object is marked as IsNew, then it will be marked as IsDirty, but if the object is marked as IsDirty, it won't necesarily be new.

Andrés

antoan replied on Friday, August 11, 2006

Does this mean that insert operations on non new, dirty children are valid framework operations?

If the thing already exist you wanna update instead of insert isn't it?

antoan replied on Friday, August 11, 2006

I finally see it, I guess in the case of an insert you could just test IsNew as only new BO's get inserted and assume the BO is infact IsDirty.

But doing : if (!this.IsDirty) return; is consistent with the check required on update.

OK its a check to see if we require an update : )

Copyright (c) Marimer LLC