Adding a secondary constructor to entity classes

Posts   
 
    
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 07-Jul-2017 18:40:04   

Hi all

I'd like to know how I can tell LLBLGen to add an additional constructor (to the parameterless one) that expects every property of the entity to be passed and then assigns the values.

Hopefully this can be achieved without taking full ownership of a template, and there is an option to let me "mix-in" stuff at certain points? Whether it is mix-in or complete replace I would like to know how it is done please.

Many thanks

Pete

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Jul-2017 09:28:56   

Hi Pete,

You can do it by adding a partial class in your Model project (the generated project):

partial class CustomerEntity
{
     public CustomerEntity(.... my parameters ...)
     {
          ....
     }
}

For more info see Adding your own code to the generated classes.

David Elizondo | LLBLGen Support Team
mrpmorris
User
Posts: 26
Joined: 07-Jul-2017
# Posted on: 10-Jul-2017 10:02:46   

daelmo wrote:

Hi Pete,

You can do it by adding a partial class in your Model project (the generated project):

partial class CustomerEntity
{
     public CustomerEntity(.... my parameters ...)
     {
          ....
     }
}

For more info see Adding your own code to the generated classes.

Thanks, but that is not what I am after. I want the auto-generator to generate that constructor so that any time the code is regenerated and a new property has been added to the class it will also be added to that constructor.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 10-Jul-2017 15:44:47   

If you want that, then create a template which creates the partial classes, and add it to the preset you're using.

Or you can use an include template to add the constructor, see the Documentation link David linked to for more details about that.

Frans Bouma | Lead developer LLBLGen Pro