Transaction combined with nested save

Posts   
 
    
JayBee
User
Posts: 280
Joined: 28-Dec-2006
# Posted on: 10-Oct-2024 15:14:24   

Hi,

I am using Self Servicing I have 3 tables Order, Orderline and Reservation. Order and Orderline have a 1:n relation. There is no direct relation between an Order and a Reservation. I would like to change the Order, OrderLines and the Reservations in one transaction. Can this be done by adding the Order and Relations to a Transaction scope and use a nested save on the Order? Will this also result in in create, update or delete actions on the Orderline entities within that sam Transaction?

Thanks for the help,

Jan

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 11-Oct-2024 08:15:39   

You don't need a transactionscope, you can use a Transaction object, add order and reservation to it, and save Order recursively, as well as reservation, then commit the transaction. See: https://www.llblgen.com/Documentation/5.11/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/SelfServicing/gencode_transactions.htm

Frans Bouma | Lead developer LLBLGen Pro
JayBee
User
Posts: 280
Joined: 28-Dec-2006
# Posted on: 14-Oct-2024 22:00:29   

So, in the first example where the order and order row are both added to the transaction, you could have also only added the order to the transaction and change the line newOrderRow.OrderID = newOrder.OrderID into newOrder.OrderDetails.Add(newOrder) or newOrderRow.Order = newOrder, and then do newOrder.Save(true)?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 15-Oct-2024 08:21:58   

JayBee wrote:

So, in the first example where the order and order row are both added to the transaction, you could have also only added the order to the transaction and change the line newOrderRow.OrderID = newOrder.OrderID into newOrder.OrderDetails.Add(newOrder) or newOrderRow.Order = newOrder, and then do newOrder.Save(true)?

To make the orderrow be saved as well, you'd need a reference to it, so indeed either newOrder.OrderDetails.Add(newOrderRow); or newOrderRow.Order=newOrder and then do a recursive save

Frans Bouma | Lead developer LLBLGen Pro
JayBee
User
Posts: 280
Joined: 28-Dec-2006
# Posted on: 15-Oct-2024 10:19:04   

Thanks.