Why IsDirty = true when I create EditableRoot?

Why IsDirty = true when I create EditableRoot?

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


phucphlq posted on Monday, April 16, 2007

Hi all!

I want whenever I create a new EditableRoot then IsDirty = false and IsNew= true;

DavidDilworth replied on Tuesday, April 17, 2007

The standard CSLA behaviour is for a "new" object to be "dirty".  This indicates that the object must be written to the database.

I would advise against changing this standard behaviour, since the CSLA framework uses the IsDirty flag internally to determine what happens when the Save() method is called.

JonM replied on Tuesday, April 17, 2007

The IsDirty is how CSLA knows whether the object needs to be saved to the database.  If the IsDirty = FALSE it will not be saved even you call a .Save().  The IsNew flag lets you know whether this object was loaded from a database or newly created.  It also directs the CSLA to call either a update or an insert.

Michael Hildner replied on Tuesday, April 17, 2007

FWIW, my subclassed EditableRoot allows one to mark the object as clean - I don't think I'm the only one doing this. I like that you can create a new object, and if you don't change anything, it won't get saved. Like how Office docs work.

phucphlq replied on Tuesday, April 17, 2007

Hi!
Why do you want to save a new EditableRoot which does not change anything?
Have you used MS Office, if you create a new doc and do not change anything, MS Office will not show question "Do you want to save the changes to Document1?".

DansDreams replied on Wednesday, April 18, 2007

I think the comparison of a busines object to a Word document might be stretching things a bit.  But really, it depends on your application's specifics.

In the business software I've used, it would be very unusual to begin the process of adding a new entity and be able to just close the form and not get a warning.  I would consider that a severe flaw, in fact.

This is somewhat a personal preference, but what would you do for cases where adding (and saving) a new item with just the default values is allowed?  If you change this behavior there would be no way for the framework to differentiate between a new item that should be saved and one that should just be ignored.

Copyright (c) Marimer LLC