Overriding an Entity Constructor

Posts   
 
    
Wiggy
User
Posts: 5
Joined: 27-Jan-2009
# Posted on: 21-Jul-2009 11:31:21   

Hi,

I had a quick question regarding the creation of new Entities. Currently when LLBLGen generates my entities are being created with a default constructor with no parameters.

public MyEntity():base() { }

If I want to be able to customise my default constructor so that I can initialise some value what is the best way for this to be done?

For example:

public MyEntity():base() { Id = new Guid(); CreatedBy = CurrentUser(); Created = DateTime.Now() }

Is it possible to stop the default constructor being automatically generated so that I can add my own Constructor between the custom user code tags??? or What is the best way to ensure that the default values are always correctly set upon the instantiation of a new object

thanks,

Wiggy

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 21-Jul-2009 16:28:57   

There are 2 options usually used. a) Have a manager/factory class create and initialise your objects for you b) You can intercept or override some of the built in code that is run when entities are created. See http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_tapinroutinesevents.htm for more details.

Matt