Default value on DTO fields

Posts   
 
    
JonE
User
Posts: 164
Joined: 15-Nov-2016
# Posted on: 06-Dec-2016 11:27:15   

Hi I am able to assign a default value to an empty dto field using this kind of setup: objectReturn = New Orm.DerivedModel.DtoClasses.CompanyDto DirectCast(objectReturn, Orm.DerivedModel.DtoClasses.CompanyDto).Enabled = True

I couldn't see a way to setup the default in the derived model setup or the entity setup screens. I have also seen the comments that the database is relied on to insert a default instead of a null value for a field.

My situation is that I use the dto to define the structure in the page and certain fields such as the enabled checkbox (above) would be best ticked by default.

Ideally I would set this up in the entity or DTO model rather than my own code (although it is nice to have the option to do it in code). Am I missing where it can be done in the model or should I just carry on using the code based approach as shown?

Regards

Jon

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 07-Dec-2016 01:41:23   

You can override OnInitializing and OnInitialized of the Entity Class which are called at the start / end resp. of InitClassEmpty.

JonE
User
Posts: 164
Joined: 15-Nov-2016
# Posted on: 07-Dec-2016 08:34:38   

Thanks for that - good to know. I take it then that there is no way to set the defaults inside the model designer?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Dec-2016 09:51:26   

No, defaults for the entity are either set in the database (the defaults for the tables you can define in the designer) or in code using a partial class.

Frans Bouma | Lead developer LLBLGen Pro