Initializing Entity Fields (Properties)

Posts   
 
    
rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 09-Nov-2007 21:19:05   

LLBL Pro version = 2.5 final runtime version = v2.0.50727 Using ASP.NET 2.0 Database = MS SQL 2005 selfsevicing

Hi,

Sorry if this is a basic question but I'm new to LLBlGen Pro and after searching the formus and faq's I can't find any satisfactory answers.

I'd would like to find out what's the best way to initialize a property of a newly created entity? I think that it should go in InitClassEmpty() method before the call to InitClassMembers(). The problem is everytime i regenerate the LLBLGen project I loose the code I've added to the InitClassEmpty() method. Can I move the //__LLBLGENPRO_USER_CODE_REGION tags up so my code will initialize my properties before the call to InitClassMemebers(). Everytime I move the user code region tags and regenerate the project the generated code is all messed up.

Please advise cry

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Nov-2007 04:37:11   

Why do you want to put your code exactly before InitClassMember()?

Anyway, while you can't move the USER_CODE_REGIONS, there are various options in your case:

  • Override OnInitialized method in a partial class and put your code there (you can check if this.IsNew to know if the entity indeed is new.

  • Override InitClassEmpty in a partial class and put your code there.

David Elizondo | LLBLGen Support Team
rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 13-Nov-2007 16:45:45   

I have an audit trail class that overrides the AuditEntityFieldSet method to capture the fields that are being changed. The fields I need to initialize when a new entity is instantiated are not suppose to get audited, so if I initialize the fields before the the call to InitClassMember() the AuditEntityFieldSet event will never get firedcand my audit trail class will not be capturing those fields I have initialized upon enity instantiation. Is there another way to accomplish the above? Am I making senseconfused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 13-Nov-2007 18:22:53   

If you want to ignore fields being audited, why don't you grab the auditor in the init method, set a property to ignore audits from then on, set the fields, and reset the flag ? In the auditEntityfieldset method you then test the flag and if its' true ignore the audit call, otherwise audit the call.

Frans Bouma | Lead developer LLBLGen Pro
rihadd
User
Posts: 22
Joined: 19-Sep-2007
# Posted on: 13-Nov-2007 19:49:15   

Thanks Otis and David,

I think Otis' solution will work best in my situation. I will be able to place my code in the between the user code region tags in the enitity class directly.