Save child/BusinessLayerLinkManager also save ParentBO


Author
Message
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Well, when you save business objects on a transaction, they are left "dirty" until you call TransactionCommit(), at which point, all of the changes to them are accepted.  Also, when you attempt to save a child business object, it will make sure that it's parent is not dirty before saving... if it is dirty, then it saves it's parent first (so that there aren't any negative FKs that need to be assigned by the server, first).

So, you can either call PinvoiceTransfer.Save(), which will cascade the saves up the parent chain, or wrap the .Save() calls with .ParentBusinessObject = Nothing and .ParentBusinessObject = parent.  If a business object doesn't have a parent, it won't try to save the parent.  So, you set the parent to nothing and then set the parent back after the save.

Chan
Chan
Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)Advanced StrataFrame User (725 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

I have a maintenance form that allow user to enter Purchase Invoice data. In same screen, I also allow user to do "immediate" stock transfer.

So, I have tables as below

PurchaseInvoice ---------<- PInvoiceTransfer ->------------- Transfers ---------<- TransferDetails
                          1:1          (n:n link table)            1:1                          1:n

Currently, I save them using transaction with following sequence

Form.Save() ------------> PurchaseInvoice
Form.AfterSave() ------------> Transfer.Save() 
                        ------------> TransferDetails.Save()
                        ------------> PinvoiceTransfer.Save()

The problem is, when I call TransferDetails.Save(), it also call Transfer.Save() since Transfer is ParentBO of TransferDetails and it is still dirty. Therefore, Transfer record will be inserted to tabel twice and cause uniqueness record error.

I tried not to call Transfer.Save(), only call TransferDetails.Save(). It works fine. This time, PInvoiceTransfer cause same problem. PInvoiceTransfer.Save() try to call Transfer.Save() also.

How could I solve this problem?

Thank you

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search