Accessing the ID of a new record after a UoW Commit

Posts   
 
    
Koolworld
User
Posts: 50
Joined: 10-Oct-2006
# Posted on: 10-Oct-2006 01:21:02   

Hi,

Can someone post a VB.Net code example of how i can obtain the database ID of a newly inserted/updated record when using LLBLGenProDataSource with livepersistance set to false.

The database inserts/updates fine using:

Protected Sub LLBLGenProDataSource1_PerformWork(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2) Handles LLBLGenProDataSource1.PerformWork e.Uow.Commit(New Transaction(IsolationLevel.ReadCommitted, "UOW"), True) End Sub

but i then want to know the PKID of the record which has been affected.

Any help would be appreciated

Regards

Dan.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Oct-2006 08:51:12   

Please check the LLBLGen Pro reference manual for UOW methods: GetUpdateQueue and GetInsertQueue

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 10-Oct-2006 09:57:28   

First call e.UoW.ConstructSaveProcessQueues() before callling GetUpdateQueue and GetInsertQueue. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Koolworld
User
Posts: 50
Joined: 10-Oct-2006
# Posted on: 10-Oct-2006 13:44:19   

Thanks for the response guys, forgot about the reference manual!

It's all working well now, im using the below to get the PKID of the affected record, is this the best way to access the PKID? Wasn't sure if there was a way of knowing what type of PerformWork it was, i.e. Update, Insert, Delete, without checking the queue.count().

Protected Sub LLBLGenProDataSource1_PerformWork(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs) Handles LLBLGenProDataSource1.PerformWork e.Uow.Commit(New Transaction(IsolationLevel.ReadCommitted, "UOW"), True)

    Dim insertQueue As List(Of ActionQueueElement(Of IEntity))
    Dim updateQueue As List(Of ActionQueueElement(Of IEntity))

    insertQueue = e.Uow.GetInsertQueue()
    updateQueue = e.Uow.GetUpdateQueue()

    If (insertQueue.Count > 0) Then
         intRecordPKID = insertQueue.Item(0).Entity.PrimaryKeyFields.Item(0).CurrentValue
    ElseIf (updateQueue.Count > 1) Then
         intRecordPKID = updateQueue.Item(0).Entity.PrimaryKeyFields.Item(0).CurrentValue
    End If

End Sub

thanks, Dan.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Oct-2006 08:56:23   

is this the best way to access the PKID?

That's alright. As ong as your only Inserting/Updating one record.