How to initilize an entity

Posts   
 
    
Behdad
User
Posts: 12
Joined: 08-Jun-2010
# Posted on: 16-Jun-2010 19:51:32   

Hi How it is possible to Initilize an entity for example give default values :set today as CreatedDate? Should I use partial classes?

Regards

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Jun-2010 09:03:10   

If you want to set the default values when saving to the database, you may set the DefaultValue directly in the database. Or you may use EntityValidation -> ValidateEntityBeforeSave to set default values in code.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 17-Jun-2010 10:11:18   

Another way is to use partial classes indeed and override OnInitialized. Be sure to test whether the Fields.EntityState flag is set to New or Fetched. (Only set your defaults when the state is New, not when the state is Fetched)

Frans Bouma | Lead developer LLBLGen Pro