modify save() method for all entities

Posts   
 
    
danielhao
User
Posts: 3
Joined: 30-Jul-2007
# Posted on: 30-Jul-2007 04:24:45   

Hi,

I want to override Save() method of EntityBase that all entities inherited from EntityBase can implement a special function like "insert a new record to 'message' table while saving based on his attribute". How can i get it?

thanks.confused

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-Jul-2007 06:29:46   

What LLBLGen version are you using? What LLBLGen Template Set are you using (Adapter | SS)?

Also read LLBLGenPro Help - (Adapter | SS) - Using generated code - Adding your own code to the generated classes

David Elizondo | LLBLGen Support Team
danielhao
User
Posts: 3
Joined: 30-Jul-2007
# Posted on: 31-Jul-2007 07:12:32   

2.0 selfservice 2 class

I know how to add my own code to generated code, but did not know how to modify EntityBase to let all inherited class inherit.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Aug-2007 05:11:27   

Override Save method in the entities you want. You can do this in a partial class:

namespace <yourProjectName>.EntityClasses
{   
    public partial class MyXEntity
    {   

         public override bool Save(IPredicate updateRestriction, bool recurse)
        {
             // your custom save code
             ...
         }
    }   
}

You can modify templates so you can include the above partial class method in all entities.

You can also use AfterSave() EventHandler to add some extra code after save.

You can also (in v2.5, now in Beta, soon in Release) inject Auditors, Validators and Authorizers to your entites, which is more suitable in these cases.

Which of those approaches is better in your project?

David Elizondo | LLBLGen Support Team
danielhao
User
Posts: 3
Joined: 30-Jul-2007
# Posted on: 10-Aug-2007 09:33:24   

Thank you.

I think it's enough for me even if i do not know how to modify templates.

Override Save method is my solution before this thread posted out, and it is my current solution too.