Any suggestion to implement custom code in onSave()

Posts   
 
    
Posts: 2
Joined: 10-May-2010
# Posted on: 11-May-2010 13:40:53   

LLBLGen pro 2.6 final. Visual Studio 2008 .NET 3.5 framework

Hello

i'm a newbie to LLBLGen pro .

I have a project to implement and i'm curently using Adapter template. I have a table "numberings" and all other tables in my database get id's from this table. I prefer to implement this logic with custom code in my entities or better in CommonEntityBase class, rather than using triggers in a database.

In particular when i insert a new entity in "beforeSave event", i want to query "numberings" table and get the current value. Then i want to increase that value and update back the new value to "numberings" table and then set the "entity.id" with the value from "numberings". Then continue saving the new Entity.

By searching the forum i figured out that i can't access the DataAccessAdapter inside an Entity...

What do you suggest as best solution for my case??

thanks in advance

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 11-May-2010 18:07:03   

What do you suggest as best solution for my case??

To be honest, don't manage Ids like this simple_smile Let the database take care of it for you using auto incrementing Id columns, that's what they're designed to do. Your approach can cause all sorts of problems, particularly with regards to performance and scalabilty.

Having said that, if you are stuck with this approach, the thing to do is to override the DataAccessAdapter's OnBeforeEntitySave method, either in a partial class or sub class, and do the work there.

Matt

Posts: 2
Joined: 10-May-2010
# Posted on: 11-May-2010 19:47:32   

Thank you Matt for your reply.

FYI : Unfortunately this aproach for id generation is not mine and i can't change it. disappointed

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 11-May-2010 23:05:08   

Always the way...

Overriding BeforeEntitySave in the adapter is the way to go then.

Matt