trigger generated PK and Refetch

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 01-Dec-2004 19:50:49   

I have the following situation (using Adapter): Table: GLMoneyWithdrawal has a PK filed MWId

PK field: MWID nvarchar(40) gets its value from an Insert Trigger on the table

LLBL code:

           Dim adapter As DataAccessAdapter = New DataAccessAdapter()
            Dim ok As Boolean = adapter.SaveEntity(Me, refetchAfterSave:=True)

I am getting an error concerning recursive save and my entity is out of sync. I read the documentation about this issue and would like the follwoing: 1- explanation why LLBL can't get this sort of auto-values from the table 2- a solution to this situation as it is impossible for me to drop my table design or my LLBL framework code (there has to be a workround for such situtions)

OMAR

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 01-Dec-2004 22:02:33   

If a trigger inserts a value, the sql code is not able to send the trigger inserted back to the caller in an output parameter. So the calling code doesn't know the PK value set by the trigger. This means that the entity is never refetchable, nor is the PK syncable with the FK's.

A workaround can be that you override OnSaveEntity(), check which entity type is saved, call a stored procedure which will return the value to make the PK, set the PK value and save the entity.

Frans Bouma | Lead developer LLBLGen Pro