Walaa wrote:
I'm not sure what you were doing as there is no code snippet.
But in general, if an entity has no changed/dirty fields, it won't be inserted nor updated, if that's what you are asking about.
Ok, further to this:
If I create a new entity then bind its fields it to a form then when the user clicks Save, it could be that some of the fields, e.g. some checkboxes, are not set (because the user wanted to leave them unchecked) causing the Save to fail.
A validator working at the property level won't pick this up because there is no problem with the property values (false is this case).
So I could:
1) In the code where the new entity is created, set default values for every field. Not really keen on this since it can be error-prone. e.g. I add a new field and forget to locate every place in the app and add the default - I won't know about the issue until it crashes at runtime.
2) I can set defaults in the entity itself as it is created. Yes, but the 'IsDirty' would be set before the user has even seen it. May not be a problem though.
3) At the point of saving, have some code that 'pokes in' the default values for non-nullable , non-PK value fields. This might work well but is there an override I can add on CommonEntityBase at the write moment?
4) Have a validator that, when everything else is valid, does the 'poking in'.
5) Have a UOW do the same thing. Is there a hook I could use to do this?
6) Have the runtime library to the poking at the right point. It should be obvious that the Save is going to fail before passing it to the DB. Can't see Frans going for this
"not the runtime library's job to check this - do it yourself!" - which is fair enough.
But which is the best way. Do you guys (or readers) have any thoughts?
Cheers
Simon