Default values for Required fields

Hi Wagner,

Another (probably newbie) question:

I have a table with a GUID ID and some ** REQUIRED ** Integer fields.  For each Integer field I specify a default value in the Data Modeler.  This produces a (SQLite) script with all defaults set correctly.

Also after browsing this forum, it appears that the generated entities (objects) do not handle defaults (i.e. there is no such attribute).  When I insert & post a record in the database (i.e. not using Aurelius), all fields are set correctly to their default value.  However, if I create a new Entity and immediately persist it through the Object Manager (** without touching any of the Integer fields **), the record is indeed inserted but with ALL Integer fields set to 0! This essentially by-passes a database rule!

Is this caused by the default property value being 0 and it being included in the Insert SQL? Only if the field is NOT Required (Nullable<Integer> property), its value defaults to NULL and the field can be excluded from the Insert SQL? Is setting default values in code (e.g. Dataset.OnNewRecord) the only - or even the required - option in such a case?

I hope my question makes sense. If not, I'll gladly explain further.

Regards,
Mark

Hi Mark,

All your assumptions are correct. So either set the field value from code, or set it as nullable and keep it NULL when inserting the record.
Hi Wagner,

Thanks for clarifying.

A Default Value attribute would be a nice feature (saving a lot of custom coding), but I suspect more people have already asked for this. Is it something that is planned for the future or is it something that is more complex than one would initially think?

Yes, it's a commonly requested feature and is planned. Yes, not a trivial one, not that easy to implement, thus it's floating in the list of priorities with other also popular requests.

I somehow suspected that (given all the possible data types and mappings).
Nevertheless, I am looking forward to it.