Common function for SAVE, INSERT, UPDATE, DELETE

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 19-Apr-2010 17:51:48   

Hi,

Instead of writing save for each table Example: CUSTOMER.SAVE, INVENTORY.SAVE, EMPLOYEE.SAVE etc.,

How can I write common function for both single and multiple tables

Example: I want to write something like

savedata [table1,table2,table3]

Here I want to pass tables as parameters.

Is this possible? If yes how ?

Regards,

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Apr-2010 07:42:33   

Not 100 %clear. could you please elaborate more? How would be such function? Do you want to save all objects passed? Have you check UnitOfWork,

You also can receive a list of EntityCollection and call save for all of them in SelfServicing (or pass them to adapter.SaveEntityCollection in Adapter).

David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 20-Apr-2010 10:30:10   

Explanation What I meant was, let us say I have 4 forms. 1. Customer 2. Material 3. Order 4. Bill

I have to write transaction management in each form then call appropriate saveentity in each form.

What I want to do is

  1. I want to avoid writing transaction management code in each form and also call to save / delete /update entity

INSTEAD,

I just want to write a class file with one function to saveentity, one to updateentity and one to deleteentity.

So it would look something like

adapter.StartTransaction(IsolationLevel.ReadCommitted, );

saveentity (table1, table2 table3 etc.) as the case may be.

This way i do not have to write CRUD procedure in each form but can write a single function and pass table names to that.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 20-Apr-2010 10:30:42   

Further, Yes i want to save all objects passed. if any one fails roll back all.

Regards,

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 20-Apr-2010 10:55:49   

You can use a UnitOfWork. Fill it up in the Form, and pass it to a method to commit it. Note: a UnitOfWork executes Updates/Inserts/Deletes entities in one transaction.